@enhance-eng/enhance 0.1.168 → 0.1.170

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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { $ as canvasAssetImportInputSchema, B as operationStatusImageSchema, Bn as domLocatorSchema, Fn as commentAuthorSchema, Ft as canvasReadInputSchema, G as canvasCaptureOutputSchema, Gn as replyCommentInputSchema, H as operationStatusOutputSchema, Hn as getCommentOutputSchema, I as canvasPrototypeInputSchema, In as commentCanvasContextSchema, It as canvasReadOutputSchema, Jn as screenElementCommentTargetSchema, Kn as replyCommentOutputSchema, Kt as parseCanvasReference, Ln as commentMessageSchema, Mt as encodeCanvasExchangeToken, N as canvasCapturePageInputSchema, P as canvasCapturePageOutputSchema, R as canvasPrototypeOutputSchema, Rn as commentResolverSchema, Rt as canvasUpdateHtmlInputSchema, S as PROTOTYPE_UPDATE_GUIDANCE, Un as listCommentsInputSchema, V as operationStatusInputSchema, Vn as elementAnchorSchema, W as canvasCaptureInputSchema, Wn as listCommentsOutputSchema, X as canvasPreparationOutputSchema, Xn as screenTextCommentTargetSchema, Y as canvasDuplicateInputSchema, Yn as screenElementsCommentTargetSchema, Z as canvasWriteReceiptSchema, Zn as startCommentInputSchema, at as canvasRenderScopedToolInputSchema, bt as canvasMakeEditableInputSchema, cn as CliError, dt as canvasCreateToolOutputSchema, et as canvasAssetImportOutputSchema, ht as createdCanvasAnswerSchema, jt as decodeCanvasExchangeToken, kt as canvasExchangeDigest, lt as canvasRemoveInputSchema, m as toMcpFailurePayload, mt as canvasFindOutputSchema, o as CAPTURE_PAGE_CALLS, pt as canvasFindInputSchema, q as canvasArrangeInputSchema, qn as screenAreaCommentTargetSchema, rn as MCP_TOOL_BY_CAPABILITY, ut as canvasCreateToolInputSchema, vt as canvasInsertHtmlInputSchema, z as canvasConversionStatusSchema, zn as commentThreadSchema } from "./cli-output-identity.lib-DMHqCPUz.mjs";
3
- import { T as createAuthUseCase, c as createOauthLoopbackAdapter, f as createCapabilityInvocationAdapter, n as createMutationKeyAdapter, r as createHttpRemoteAdapter, u as withCapabilityNames, y as boundedResultPage } from "./zod-messages.lib-T23QiUQO.mjs";
4
- import { a as mcpDispatchedResultSchema, c as createCapabilityCatalogAdapter, i as createMcpCanvasToolsAdapter, n as createMcpWorkflowsAdapter, o as createMcpResultAdapter, r as createMcpClientInvocationAdapter, s as createMcpClientContextAdapter } from "./mcp-server.adapter-CUuoL6AI.mjs";
2
+ import { $ as canvasAssetImportInputSchema, $n as screenTextCommentTargetSchema, B as operationStatusImageSchema, Bn as commentMessageSchema, Ft as canvasExchangeDigest, G as canvasCaptureOutputSchema, Gn as getCommentOutputSchema, H as operationStatusOutputSchema, Hn as commentThreadSchema, Ht as canvasReadOutputSchema, I as canvasPrototypeInputSchema, Jn as replyCommentInputSchema, Kn as listCommentsInputSchema, Lt as decodeCanvasExchangeToken, N as canvasCapturePageInputSchema, P as canvasCapturePageOutputSchema, Pt as parseCanvasReference, Qn as screenElementsCommentTargetSchema, R as canvasPrototypeOutputSchema, Rn as commentAuthorSchema, Rt as encodeCanvasExchangeToken, S as PROTOTYPE_UPDATE_GUIDANCE, Un as domLocatorSchema, V as operationStatusInputSchema, Vn as commentResolverSchema, Vt as canvasReadInputSchema, W as canvasCaptureInputSchema, Wn as elementAnchorSchema, Wt as canvasUpdateHtmlInputSchema, X as canvasPreparationOutputSchema, Xn as screenAreaCommentTargetSchema, Y as canvasDuplicateInputSchema, Yn as replyCommentOutputSchema, Z as canvasWriteReceiptSchema, Zn as screenElementCommentTargetSchema, an as MCP_TOOL_BY_CAPABILITY, at as canvasRenderScopedToolInputSchema, bt as canvasMakeEditableInputSchema, dn as CliError, dt as canvasCreateToolOutputSchema, er as startCommentInputSchema, et as canvasAssetImportOutputSchema, ht as createdCanvasAnswerSchema, lt as canvasRemoveInputSchema, m as toMcpFailurePayload, mt as canvasFindOutputSchema, o as CAPTURE_PAGE_CALLS, pt as canvasFindInputSchema, q as canvasArrangeInputSchema, qn as listCommentsOutputSchema, ut as canvasCreateToolInputSchema, vt as canvasInsertHtmlInputSchema, z as canvasConversionStatusSchema, zn as commentCanvasContextSchema } from "./cli-output-identity.lib-CKns8qEG.mjs";
3
+ import { T as createAuthUseCase, c as createOauthLoopbackAdapter, f as createCapabilityInvocationAdapter, n as createMutationKeyAdapter, r as createHttpRemoteAdapter, u as withCapabilityNames, y as boundedResultPage } from "./zod-messages.lib-G2BtVFRk.mjs";
4
+ import { a as mcpDispatchedResultSchema, c as withClientTokenNamed, i as createMcpCanvasToolsAdapter, l as createMcpClientContextAdapter, n as createMcpWorkflowsAdapter, o as createMcpResultAdapter, r as createMcpClientInvocationAdapter, s as toolClientToken, u as createCapabilityCatalogAdapter } from "./mcp-server.adapter-UiOcYGPZ.mjs";
5
5
  import { z } from "zod";
6
6
  import { McpServer } from "@modelcontextprotocol/server";
7
7
 
@@ -80,7 +80,7 @@ const READ_ANNOTATIONS = {
80
80
  idempotentHint: true,
81
81
  openWorldHint: false
82
82
  };
83
- const delivered$1 = async (schema, action) => {
83
+ const answered = async (schema, action) => {
84
84
  try {
85
85
  const result = schema.parse(await action());
86
86
  return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
@@ -88,6 +88,11 @@ const delivered$1 = async (schema, action) => {
88
88
  return createMcpResultAdapter("Reconnect Enhance through this host’s connection flow, then repeat the request.").failure(error);
89
89
  }
90
90
  };
91
+ /** A write's answer, which names the retry token it used: the agent's, or one the tool made. */
92
+ const delivered$1 = async (schema, given, action) => {
93
+ const clientToken = toolClientToken(given);
94
+ return withClientTokenNamed(await answered(schema, async () => action(clientToken)), clientToken);
95
+ };
91
96
  const registerRemoval = (server, invoke) => {
92
97
  server.registerTool("canvas_remove", {
93
98
  title: "Remove canvas objects",
@@ -99,7 +104,7 @@ const registerRemoval = (server, invoke) => {
99
104
  readOnlyHint: false,
100
105
  destructiveHint: true
101
106
  }
102
- }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasWriteReceiptSchema, async () => invoke("canvas.remove", args, clientToken))));
107
+ }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasWriteReceiptSchema, clientToken, async (token) => invoke("canvas.remove", args, token))));
103
108
  };
104
109
  const registerExchange = (server, invoke, isReadOnly) => {
105
110
  server.registerTool("canvas_read", {
@@ -108,7 +113,7 @@ const registerExchange = (server, invoke, isReadOnly) => {
108
113
  inputSchema: canvasReadInputSchema,
109
114
  outputSchema: canvasReadOutputSchema,
110
115
  annotations: READ_ANNOTATIONS
111
- }, async (args, context) => clientContext$9.run(context, async () => delivered$1(canvasReadOutputSchema, async () => invoke("canvas.read", args))));
116
+ }, async (args, context) => clientContext$9.run(context, async () => answered(canvasReadOutputSchema, async () => invoke("canvas.read", args))));
112
117
  if (isReadOnly) return;
113
118
  server.registerTool("canvas_update_html", {
114
119
  title: "Update editable canvas content",
@@ -120,7 +125,7 @@ const registerExchange = (server, invoke, isReadOnly) => {
120
125
  readOnlyHint: false,
121
126
  destructiveHint: true
122
127
  }
123
- }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasPreparationOutputSchema, async () => invoke("canvas.updateHtml", args, clientToken))));
128
+ }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasPreparationOutputSchema, clientToken, async (token) => invoke("canvas.updateHtml", args, token))));
124
129
  };
125
130
  const registerInsertion = (server, invoke) => {
126
131
  server.registerTool("canvas_insert_html", {
@@ -132,19 +137,19 @@ const registerInsertion = (server, invoke) => {
132
137
  ...READ_ANNOTATIONS,
133
138
  readOnlyHint: false
134
139
  }
135
- }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasConversionStatusSchema, async () => invoke("canvas.insertHtml", args, clientToken))));
140
+ }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasConversionStatusSchema, clientToken, async (token) => invoke("canvas.insertHtml", args, token))));
136
141
  };
137
142
  const registerConversion = (server, invoke) => {
138
143
  server.registerTool("canvas_capture", {
139
144
  title: "Capture a recording moment",
140
- description: "Land an exact recording moment as an editable frame after inspecting its canvas_render preview. Supply that preview job, the canvas version that preview rendered (baseVersion) and the full page/selection reference. The page is stored, compiled into editable layers and saved as one frame below the root-level recording on the same page, in one change at baseVersion. When attachment is committed, frame.nodeId is the editable frame (edit its layers) and frame.version is the canvas version to use as your next baseVersion; canvas_make_editable is not needed. A concurrent canvas edit prevents the save: render a new preview and capture with a new clientToken. When attachment is pending, repeat with identical arguments and the same clientToken, or follow its operation with operation_status; a new token could save a second frame. When attachment is not_confirmed with a failure, nothing was added: capture again with a new clientToken. This supports recordings already on this canvas, not arbitrary URLs or prototype crawling.",
145
+ description: "Land an exact recording moment as an editable frame after inspecting its canvas_render preview. Supply that preview job, the canvas version that preview rendered (baseVersion) and the full page/selection reference. The page is stored, compiled into editable layers and saved as one frame below the root-level recording on the same page, in one change at baseVersion. When attachment is committed, frame.nodeId is the editable frame (edit its layers) and frame.version is the canvas version to use as your next baseVersion; canvas_make_editable is not needed. A concurrent canvas edit prevents the save: render a new preview and capture again without the clientToken, so the tool makes a new one. When attachment is pending, repeat with identical arguments and the same clientToken, or follow its operation with operation_status; a new token could save a second frame. When attachment is not_confirmed with a failure, nothing was added: capture again without the clientToken. This supports recordings already on this canvas, not arbitrary URLs or prototype crawling.",
141
146
  inputSchema: canvasCaptureInputSchema,
142
147
  outputSchema: canvasCaptureOutputSchema,
143
148
  annotations: {
144
149
  ...READ_ANNOTATIONS,
145
150
  readOnlyHint: false
146
151
  }
147
- }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasCaptureOutputSchema, async () => invoke("canvas.capture", args, clientToken))));
152
+ }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasCaptureOutputSchema, clientToken, async (token) => invoke("canvas.capture", args, token))));
148
153
  server.registerTool("canvas_capture_page", {
149
154
  title: "Capture a page you opened",
150
155
  description: `Put any page you can open on a canvas as an editable frame: a page on localhost, behind a sign-in, or anywhere else your browser can reach. Enhance never visits the address itself. ${CAPTURE_PAGE_CALLS_FOR_TOOLS} A picture of the page lands at once at that place, and becomes the editable frame in place, keeping its id. When step is placed, frame.nodeId is the editable frame, frame.version is your next baseVersion and frame.box tells you where to put the next capture. When step is converting, the picture is on the canvas: repeat with identical arguments and clientToken. If a page's Content Security Policy blocks the snippet, run it from Playwright in a context created with bypassCSP: true.`,
@@ -154,7 +159,7 @@ const registerConversion = (server, invoke) => {
154
159
  ...READ_ANNOTATIONS,
155
160
  readOnlyHint: false
156
161
  }
157
- }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasCapturePageOutputSchema, async () => invoke("canvas.capturePage", args, clientToken))));
162
+ }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasCapturePageOutputSchema, clientToken, async (token) => invoke("canvas.capturePage", args, token))));
158
163
  server.registerTool("canvas_make_editable", {
159
164
  title: "Make a captured screen editable",
160
165
  description: "Convert one supported, root-level captured screen into a new editable subtree beside its source. Preserve the complete page/selection reference. The original screen is retained. This does not reconstruct raster images, crawl prototypes or capture arbitrary websites. The call normally answers with the result and its bounded loss report; operation_status is for a conversion that outlasts the wait, and for remaining mappings. Render the original and result for comparison. Retry uncertainty with identical arguments and clientToken.",
@@ -164,7 +169,7 @@ const registerConversion = (server, invoke) => {
164
169
  ...READ_ANNOTATIONS,
165
170
  readOnlyHint: false
166
171
  }
167
- }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasConversionStatusSchema, async () => invoke("canvas.makeEditable", args, clientToken))));
172
+ }, async ({ clientToken, ...args }, context) => clientContext$9.run(context, async () => delivered$1(canvasConversionStatusSchema, clientToken, async (token) => invoke("canvas.makeEditable", args, token))));
168
173
  };
169
174
  const createMcpCanvasContentAdapter = (invoke, isReadOnly) => ({ register: (server) => {
170
175
  server.registerResource("canvas-html-v2", CANVAS_HTML_REFERENCE_URI, {
@@ -293,8 +298,9 @@ const createMcpCanvasPreparationAdapter = (invoke) => ({ register: (server) => {
293
298
  openWorldHint: false
294
299
  }
295
300
  }, async (offered, context) => clientContext$7.run(context, async () => {
296
- const { clientToken, ...args } = definition.inputSchema.parse(offered);
297
- return deliverPreparation(async () => invoke(definition.capability, args, clientToken));
301
+ const { clientToken: given, ...args } = definition.inputSchema.parse(offered);
302
+ const clientToken = toolClientToken(given);
303
+ return withClientTokenNamed(await deliverPreparation(async () => invoke(definition.capability, args, clientToken)), clientToken);
298
304
  }));
299
305
  } });
300
306
 
@@ -314,19 +320,20 @@ const createMcpCanvasRenderAdapter = (input) => ({ register: (server) => {
314
320
  idempotentHint: true,
315
321
  openWorldHint: false
316
322
  }
317
- }, async ({ clientToken, ...request }, context) => clientContext$6.run(context, async () => {
323
+ }, async ({ clientToken: given, ...request }, context) => clientContext$6.run(context, async () => {
318
324
  const results = createMcpResultAdapter("Reconnect Enhance and retry this same render intent.");
325
+ const clientToken = toolClientToken(given);
319
326
  try {
320
- return {
327
+ return withClientTokenNamed({
321
328
  ...await results.success(server, await input.invocation.invoke({
322
329
  capability: fromCapabilityReference(input.catalog, "canvas.render"),
323
330
  arguments: request,
324
331
  clientToken
325
332
  }), "embedded"),
326
333
  ...input.ui !== void 0 && { _meta: input.ui.resultMeta }
327
- };
334
+ }, clientToken);
328
335
  } catch (error) {
329
- return results.failure(error);
336
+ return withClientTokenNamed(results.failure(error), clientToken);
330
337
  }
331
338
  }));
332
339
  } });
@@ -1162,12 +1169,13 @@ const createMcpPrototypePublishAdapter = (invoke) => ({ register: (server) => {
1162
1169
  idempotentHint: true,
1163
1170
  openWorldHint: true
1164
1171
  }
1165
- }, async ({ clientToken, ...args }, context) => clientContext$2.run(context, async () => {
1172
+ }, async ({ clientToken: given, ...args }, context) => clientContext$2.run(context, async () => {
1173
+ const clientToken = toolClientToken(given);
1166
1174
  try {
1167
1175
  const result = canvasPrototypeOutputSchema.parse(await invoke("prototype.publishCanvas", args, clientToken));
1168
- return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
1176
+ return withClientTokenNamed(createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result), clientToken);
1169
1177
  } catch (error) {
1170
- return createMcpResultAdapter("Retry the original publishing request and clientToken after reconnecting; do not infer that a lost response means no changes.").failure(error);
1178
+ return withClientTokenNamed(createMcpResultAdapter("Retry the original publishing request and clientToken after reconnecting; do not infer that a lost response means no changes.").failure(error), clientToken);
1171
1179
  }
1172
1180
  }));
1173
1181
  } });
@@ -1188,12 +1196,14 @@ const createMcpAssetImportAdapter = (invoke) => ({ register: (server) => {
1188
1196
  openWorldHint: false
1189
1197
  }
1190
1198
  }, async (offered, context) => clientContext$1.run(context, async () => {
1199
+ let clientToken = toolClientToken(void 0);
1191
1200
  try {
1192
- const { clientToken, ...input } = canvasAssetImportInputSchema.parse(offered);
1201
+ const { clientToken: given, ...input } = canvasAssetImportInputSchema.parse(offered);
1202
+ clientToken = toolClientToken(given);
1193
1203
  const result = canvasAssetImportOutputSchema.parse(await invoke("canvas.importAsset", input, clientToken));
1194
- return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
1204
+ return withClientTokenNamed(createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result), clientToken);
1195
1205
  } catch (error) {
1196
- return createMcpResultAdapter("Retry the same selected file and clientToken.").failure(error);
1206
+ return withClientTokenNamed(createMcpResultAdapter("Retry the same selected file and clientToken.").failure(error), clientToken);
1197
1207
  }
1198
1208
  }));
1199
1209
  } });
@@ -1268,6 +1278,13 @@ const createMcpCanvasProfileAdapter = (input) => {
1268
1278
 
1269
1279
  //#endregion
1270
1280
  //#region src/infrastructure/desktop-scoped-remote.adapter.ts
1281
+ /** The writes a desktop chat records and keeps inside its selection. */
1282
+ const WRITE_PROCEDURES = /* @__PURE__ */ new Set([
1283
+ "canvas.applyOperations",
1284
+ "canvas.render.importSource",
1285
+ "canvas.applyEdits"
1286
+ ]);
1287
+ const isWriteProcedure = (procedure) => WRITE_PROCEDURES.has(procedure);
1271
1288
  const argumentSchema = z.looseObject({ canvasId: z.uuid() });
1272
1289
  const mutationSchema = argumentSchema.extend({ mutationId: z.uuid() });
1273
1290
  const createDesktopScopedRemoteAdapter = (remote, scope, observer, mutationKey) => ({
@@ -1275,8 +1292,11 @@ const createDesktopScopedRemoteAdapter = (remote, scope, observer, mutationKey)
1275
1292
  mutate: async (procedure, input) => {
1276
1293
  const args = argumentSchema.parse(input);
1277
1294
  if (args.canvasId !== scope.canvasId) throw new CliError("FORBIDDEN", "This write belongs to another canvas.", "Start a new chat there.");
1278
- const isWriting = procedure === "canvas.applyOperations" || procedure === "canvas.render.importSource";
1279
- const scoped = isWriting ? {
1295
+ const isWriting = isWriteProcedure(procedure);
1296
+ const scoped = isWriting ? procedure === "canvas.applyEdits" ? {
1297
+ ...args,
1298
+ scopeNodeIds: scope.nodeIds
1299
+ } : {
1280
1300
  ...args,
1281
1301
  ...procedure === "canvas.render.importSource" && { mutationId: mutationKey?.current(procedure, args) },
1282
1302
  writeScope: { rootIds: scope.nodeIds }
package/dist/mcp-main.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { s as toCapabilityDefinition } from "./cli-output-identity.lib-DMHqCPUz.mjs";
3
- import { a as readLocalMcpEnvironment, t as installZodMessages } from "./zod-messages.lib-T23QiUQO.mjs";
2
+ import { s as toCapabilityDefinition } from "./cli-output-identity.lib-CKns8qEG.mjs";
3
+ import { a as readLocalMcpEnvironment, t as installZodMessages } from "./zod-messages.lib-G2BtVFRk.mjs";
4
4
  import { t as createFileCredentialAdapter } from "./file-credential.adapter-CShGZcd5.mjs";
5
- import { c as createCapabilityCatalogAdapter, s as createMcpClientContextAdapter, t as createMcpServerAdapter } from "./mcp-server.adapter-CUuoL6AI.mjs";
6
- import { n as createMcpCanvasProfileAdapter, t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-YFCrLzlc.mjs";
5
+ import { l as createMcpClientContextAdapter, t as createMcpServerAdapter, u as createCapabilityCatalogAdapter } from "./mcp-server.adapter-UiOcYGPZ.mjs";
6
+ import { n as createMcpCanvasProfileAdapter, t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-BfWB3PFL.mjs";
7
7
  import process from "node:process";
8
8
  import { z } from "zod";
9
9
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
@@ -171,19 +171,19 @@ const clientContext = createMcpClientContextAdapter();
171
171
  const main = () => {
172
172
  const config = readLocalMcpEnvironment();
173
173
  const credentials = createFileCredentialAdapter(config.configDirectory, config.earlierConfigDirectory);
174
- const invocation = createMcpInvocationAdapter(config.apiUrl, credentials, config.configDirectory, { version: "0.1.168" });
174
+ const invocation = createMcpInvocationAdapter(config.apiUrl, credentials, config.configDirectory, { version: "0.1.170" });
175
175
  const catalog = [...createCapabilityCatalogAdapter(), ...createMcpTransportCapabilityAdapter()];
176
176
  const client = clientContext.createStdio();
177
177
  serveStdio(() => config.profile === "canvas" ? createMcpCanvasProfileAdapter({
178
178
  readOnly: config.isReadOnly,
179
179
  ...config.workflowsDirectory !== void 0 && { workflows: config.workflowsDirectory },
180
180
  name: config.mcpServiceName,
181
- version: "0.1.168",
181
+ version: "0.1.170",
182
182
  invocation,
183
183
  clientMetadata: client.metadata,
184
184
  catalog
185
185
  }) : createMcpServerAdapter({
186
- version: "0.1.168",
186
+ version: "0.1.170",
187
187
  name: config.mcpServiceName,
188
188
  commandName: config.commandName,
189
189
  invocation,
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { Br as canvasRenderTargetSchema, D as canvasWriteHtmlCapabilityInputSchema, Gt as hasCanvasReferenceScope, Kt as parseCanvasReference, Nr as wholeCanvasDocumentOutputSchema, Rr as canvasRenderSourceStateSchema, Ut as canvasReferenceRenderTarget, an as SKILL_NAMES, cn as CliError, d as createMcpCapabilityDiscoveryAdapter, gr as agentClientMetadata, i as createLazyCapabilityCatalogAdapter, in as SKILL_JOBS, l as toPresentedCapabilities, m as toMcpFailurePayload, n as withCommandName, nn as onSurface, nt as canvasRenderBatchResultSchema, qt as readStoredCanvasScene, r as toCanvasAuthoringResult, st as canvasRenderFileSchema, t as withCommandInFailure, wt as inputProblemFields, xt as canvasEditCapabilityInputSchema } from "./cli-output-identity.lib-DMHqCPUz.mjs";
2
+ import { D as canvasWriteHtmlCapabilityInputSchema, Gt as retryClientTokenSchema, Nr as wholeCanvasDocumentOutputSchema, Nt as hasCanvasReferenceScope, Pt as parseCanvasReference, Yt as readStoredCanvasScene, cn as SKILL_NAMES, d as createMcpCapabilityDiscoveryAdapter, dn as CliError, i as createLazyCapabilityCatalogAdapter, in as onSurface, jt as canvasReferenceRenderTarget, l as toPresentedCapabilities, li as canvasRenderTargetSchema, m as toMcpFailurePayload, n as withCommandName, nt as canvasRenderBatchResultSchema, r as toCanvasAuthoringResult, si as canvasRenderSourceStateSchema, sn as SKILL_JOBS, st as canvasRenderFileSchema, t as withCommandInFailure, wt as inputProblemFields, xt as canvasEditCapabilityInputSchema, yr as agentClientMetadata } from "./cli-output-identity.lib-CKns8qEG.mjs";
3
3
  import { z } from "zod";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
5
5
  import { readFile, rm } from "node:fs/promises";
@@ -80,6 +80,22 @@ const createMcpClientContextAdapter = () => ({
80
80
  createStdio: createMcpStdioClientAdapter
81
81
  });
82
82
 
83
+ //#endregion
84
+ //#region src/infrastructure/mcp-client-token.lib.ts
85
+ /** A write's retry token: the one the agent gave, or a new random one the tool makes. */
86
+ const toolClientToken = (given) => given ?? randomUUID();
87
+ /**
88
+ * The answer with its retry token named, so an agent never makes one up: it repeats the call with
89
+ * this token only when the outcome was uncertain.
90
+ */
91
+ const withClientTokenNamed = (answer, clientToken) => ({
92
+ ...answer,
93
+ content: [...answer.content, {
94
+ type: "text",
95
+ text: `clientToken: ${clientToken}. Repeat this call with identical arguments and this clientToken only if its outcome was uncertain.`
96
+ }]
97
+ });
98
+
83
99
  //#endregion
84
100
  //#region src/infrastructure/mcp-render-attachment.adapter.ts
85
101
  const createMcpRenderAttachmentAdapter = async (server, result, delivery) => {
@@ -481,7 +497,7 @@ const mcpMutationInputSchema = z.object({
481
497
  //#endregion
482
498
  //#region src/infrastructure/mcp-canvas-tools.adapter.ts
483
499
  const clientContext$2 = createMcpClientContextAdapter();
484
- const clientToken = z.uuid().optional().describe("Reuse only when retrying this exact mutation.");
500
+ const clientTokenSchema = retryClientTokenSchema;
485
501
  const writeSchema = canvasWriteHtmlCapabilityInputSchema.pick({
486
502
  baseVersion: true,
487
503
  targetNodeId: true,
@@ -490,11 +506,11 @@ const writeSchema = canvasWriteHtmlCapabilityInputSchema.pick({
490
506
  }).extend({
491
507
  canvas: z.string().min(1).describe("Canvas UUID or complete canvas/page/selection URL. Preserve every supplied page and selection."),
492
508
  mode: z.enum(["insert-children", "replace"]).default("insert-children"),
493
- clientToken
509
+ clientToken: clientTokenSchema
494
510
  });
495
- const editSchema = canvasEditCapabilityInputSchema.extend({ clientToken });
511
+ const editSchema = canvasEditCapabilityInputSchema.extend({ clientToken: clientTokenSchema });
496
512
  const renderSchema = z.object({
497
- clientToken,
513
+ clientToken: clientTokenSchema,
498
514
  canvas: z.string().min(1),
499
515
  expectedVersion: z.number().int().positive().describe("Version returned by the latest successful read or write."),
500
516
  target: canvasRenderTargetSchema.default({ kind: "content" }),
@@ -525,11 +541,13 @@ const renderTarget = async (input, args) => {
525
541
  target: canvasReferenceRenderTarget(reference, readStoredCanvasScene(held.document), args.target)
526
542
  };
527
543
  };
528
- const deliver = async (server, input, action) => {
544
+ /** A write's answer, which names the retry token it used: the agent's, or one the tool made. */
545
+ const deliver = async (server, input, given, action) => {
546
+ const clientToken = toolClientToken(given);
529
547
  try {
530
- return await input.results.success(server, await action(), input.delivery);
548
+ return withClientTokenNamed(await input.results.success(server, await action(clientToken), input.delivery), clientToken);
531
549
  } catch (error) {
532
- return input.results.failure(error);
550
+ return withClientTokenNamed(input.results.failure(error), clientToken);
533
551
  }
534
552
  };
535
553
  const registerWrite = (server, input) => {
@@ -544,7 +562,7 @@ const registerWrite = (server, input) => {
544
562
  idempotentHint: false,
545
563
  openWorldHint: false
546
564
  }
547
- }, async ({ canvas, clientToken: token, ...args }, context) => clientContext$2.run(context, async () => deliver(server, input, async () => {
565
+ }, async ({ canvas, clientToken: token, ...args }, context) => clientContext$2.run(context, async () => deliver(server, input, token, async (clientToken) => {
548
566
  const reference = parseCanvasReference(canvas);
549
567
  return invoke(input, "canvas.writeHtml", {
550
568
  ...args,
@@ -556,7 +574,7 @@ const registerWrite = (server, input) => {
556
574
  overwriteRender: false,
557
575
  renderScale: 1,
558
576
  renderTimeoutMs: 12e4
559
- }, token ?? null);
577
+ }, clientToken);
560
578
  })));
561
579
  };
562
580
  const registerEdit = (server, input) => {
@@ -571,7 +589,7 @@ const registerEdit = (server, input) => {
571
589
  idempotentHint: false,
572
590
  openWorldHint: false
573
591
  }
574
- }, async ({ clientToken: token, ...args }, context) => clientContext$2.run(context, async () => deliver(server, input, async () => invoke(input, "canvas.edit", args, token ?? null))));
592
+ }, async ({ clientToken: token, ...args }, context) => clientContext$2.run(context, async () => deliver(server, input, token, async (clientToken) => invoke(input, "canvas.edit", args, clientToken))));
575
593
  };
576
594
  const registerRender = (server, input) => {
577
595
  if (input.catalog.some((capability) => capability.id === "canvas.render")) server.registerTool("canvas_render", {
@@ -585,7 +603,7 @@ const registerRender = (server, input) => {
585
603
  idempotentHint: false,
586
604
  openWorldHint: false
587
605
  }
588
- }, async (args, context) => clientContext$2.run(context, async () => deliver(server, input, async () => invoke(input, "canvas.render", {
606
+ }, async (args, context) => clientContext$2.run(context, async () => deliver(server, input, args.clientToken, async (clientToken) => invoke(input, "canvas.render", {
589
607
  ...await renderTarget(input, args),
590
608
  expectedVersion: args.expectedVersion,
591
609
  sourceState: args.sourceState,
@@ -593,7 +611,7 @@ const registerRender = (server, input) => {
593
611
  outputPath: null,
594
612
  overwrite: false,
595
613
  timeoutMs: 12e4
596
- }, args.clientToken ?? null))));
614
+ }, clientToken))));
597
615
  };
598
616
  const createMcpCanvasToolsAdapter = (input) => ({ register: (server) => {
599
617
  const selected = input.tools ?? [
@@ -897,4 +915,4 @@ const createMcpServerAdapter = (input) => {
897
915
  };
898
916
 
899
917
  //#endregion
900
- export { mcpDispatchedResultSchema as a, createCapabilityCatalogAdapter as c, createMcpCanvasToolsAdapter as i, createMcpWorkflowsAdapter as n, createMcpResultAdapter as o, createMcpClientInvocationAdapter as r, createMcpClientContextAdapter as s, createMcpServerAdapter as t };
918
+ export { mcpDispatchedResultSchema as a, withClientTokenNamed as c, createMcpCanvasToolsAdapter as i, createMcpClientContextAdapter as l, createMcpWorkflowsAdapter as n, createMcpResultAdapter as o, createMcpClientInvocationAdapter as r, toolClientToken as s, createMcpServerAdapter as t, createCapabilityCatalogAdapter as u };
package/dist/mcp.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { u as toSharedCapabilities } from "./cli-output-identity.lib-DMHqCPUz.mjs";
2
+ import { u as toSharedCapabilities } from "./cli-output-identity.lib-CKns8qEG.mjs";
3
3
  import { t as toCapabilityInventory } from "./capability-inventory.mapper-DyYXyVBJ.mjs";
4
- import { c as createCapabilityCatalogAdapter, t as createMcpServerAdapter } from "./mcp-server.adapter-CUuoL6AI.mjs";
4
+ import { t as createMcpServerAdapter, u as createCapabilityCatalogAdapter } from "./mcp-server.adapter-UiOcYGPZ.mjs";
5
5
 
6
6
  export { createCapabilityCatalogAdapter, createMcpServerAdapter as createEnhanceMcpServer, toCapabilityInventory, toSharedCapabilities };
@@ -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 { $ as canvasAssetImportInputSchema, An as getMeOutputSchema, L as canvasPrototypeIntentSchema, On as prototypeArtifactPathSchema, R as canvasPrototypeOutputSchema, S as PROTOTYPE_UPDATE_GUIDANCE, an as MCP_TOOL_BY_CAPABILITY, dn as CliError, et as canvasAssetImportOutputSchema, jn as MCP_AUTH_SCOPE, ln as skillTextsFor, wn as foldPrototypeArtifactPath, yi as signedDownloadSchema } from "./cli-output-identity.lib-CKns8qEG.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-G2BtVFRk.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-UiOcYGPZ.mjs";
5
+ import { n as createMcpCanvasProfileAdapter, t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-BfWB3PFL.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,12 +549,14 @@ 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) => {
@@ -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.170",
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
  });