@superblocksteam/cli 2.0.155-next.3 → 2.0.156-next.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.
Files changed (119) hide show
  1. package/README.md +1 -1
  2. package/bin/dev.js +6 -0
  3. package/bin/run.js +6 -0
  4. package/dist/{acorn-R44QJXGX.js → acorn-DGX7PYLV.js} +3 -3
  5. package/dist/{angular-32M7AVGS.js → angular-R4NX53UH.js} +3 -3
  6. package/dist/{api-WIV6M7TY.js → api-PUBF6KGO.js} +4 -4
  7. package/dist/{babel-PFQW4XYW.js → babel-7RVI34KO.js} +3 -3
  8. package/dist/{chunk-4T3WLZPG.js → chunk-2UIYBP3A.js} +3 -3
  9. package/dist/{chunk-DJMTVLRU.js → chunk-5Q5V3TET.js} +3 -3
  10. package/dist/{chunk-OZ4CSS7U.js → chunk-6FY2V2IK.js} +4 -4
  11. package/dist/{chunk-IIZNQTMP.js → chunk-FOBDVZDC.js} +4 -4
  12. package/dist/{chunk-ZDJ4PS2J.js → chunk-G3BZOYGH.js} +4 -4
  13. package/dist/{chunk-EB6EWBNB.js → chunk-GSEYYU3O.js} +4862 -2869
  14. package/dist/{chunk-EB6EWBNB.js.map → chunk-GSEYYU3O.js.map} +1 -1
  15. package/dist/{chunk-VC5KDSHO.js → chunk-HIJTEOLS.js} +3 -3
  16. package/dist/{chunk-DB3LEK4O.js → chunk-HL25LM4M.js} +3 -3
  17. package/dist/{chunk-VC6MXN5M.js → chunk-JMVQQKJH.js} +4 -4
  18. package/dist/{chunk-VJIYWOYI.js → chunk-JPPNFPS7.js} +3 -3
  19. package/dist/{chunk-4ZEAMO2U.js → chunk-KCSBSTLV.js} +2 -2
  20. package/dist/{chunk-6LFVTDU2.js → chunk-SAWXWFA5.js} +3 -3
  21. package/dist/{chunk-TGCCW35O.js → chunk-TGRVOJ2E.js} +3 -3
  22. package/dist/{chunk-TIXWC3AJ.js → chunk-TWCRH5BC.js} +3758 -157
  23. package/dist/chunk-TWCRH5BC.js.map +1 -0
  24. package/dist/{chunk-EQFSCQQM.js → chunk-XB77S427.js} +8 -8
  25. package/dist/{chunk-RPVWH5XI.js → chunk-XDZLYZIH.js} +3 -3
  26. package/dist/{chunk-MEJXCYPE.js → chunk-XIUG55BY.js} +3 -3
  27. package/dist/{chunk-D4566SJ7.js → chunk-YYWYPK75.js} +3 -3
  28. package/dist/{chunk-LVBXHCNA.js → chunk-Z2REETG5.js} +5 -5
  29. package/dist/{chunk-WEX5IXBC.js → chunk-ZWPASRGT.js} +3 -3
  30. package/dist/{cli-truncate-L4JXF7K6.js → cli-truncate-4EMBJY7A.js} +5 -5
  31. package/dist/commands/dev-parent.js +3 -3
  32. package/dist/{dd-trace-V65JTNHD.js → dd-trace-6GDHAGGU.js} +6 -6
  33. package/dist/{dist-Q3R2FBE2.js → dist-5JXJ7LYZ.js} +15 -15
  34. package/dist/{dist-T7YMQ4FI.js → dist-Y4DZZVYZ.js} +839 -200
  35. package/dist/dist-Y4DZZVYZ.js.map +1 -0
  36. package/dist/{embedded-playwright-mcp-server-XVYGQCP2.js → embedded-playwright-mcp-server-QIV5UP2O.js} +3 -3
  37. package/dist/{enquirer-YVBWN72T.js → enquirer-N2JRBZF7.js} +4 -4
  38. package/dist/{estree-6PWHHM2H.js → estree-HCHNQOO2.js} +3 -3
  39. package/dist/{flow-KCVOER5U.js → flow-UMJJW5UK.js} +3 -3
  40. package/dist/{getMachineId-bsd-D5RAZQ2D.js → getMachineId-bsd-HYDQSXAS.js} +5 -5
  41. package/dist/{getMachineId-darwin-BSFO7XMW.js → getMachineId-darwin-EFSF4DUT.js} +5 -5
  42. package/dist/{getMachineId-linux-6NVJ5V5T.js → getMachineId-linux-WLTMPU7W.js} +4 -4
  43. package/dist/{getMachineId-unsupported-4VOVSAF3.js → getMachineId-unsupported-2M2LW2NR.js} +4 -4
  44. package/dist/{getMachineId-win-YUDPXOPQ.js → getMachineId-win-UNYCQSBF.js} +5 -5
  45. package/dist/{glimmer-V64NM4J5.js → glimmer-XSXAY37I.js} +3 -3
  46. package/dist/{graphql-B6AYKOKI.js → graphql-IH2EYV52.js} +3 -3
  47. package/dist/{html-ZBVVO3ZX.js → html-23SNBE4X.js} +3 -3
  48. package/dist/{http-L4BTSYOU.js → http-SBMHFWHF.js} +14 -14
  49. package/dist/index.js +23 -23
  50. package/dist/{jiti-R3YSBCRO.js → jiti-GRIYEDYH.js} +3 -3
  51. package/dist/{log-update-KVOLYFCC.js → log-update-4GNKHCTM.js} +6 -6
  52. package/dist/{markdown-REEFWBCX.js → markdown-V6KHVZDT.js} +3 -3
  53. package/dist/{meriyah-T5IDFQVO.js → meriyah-CXWFY3WL.js} +3 -3
  54. package/dist/{postcss-3EBJ7C2O.js → postcss-23O3XFEP.js} +3 -3
  55. package/dist/{read-pkg-6Z3BVK5L.js → read-pkg-SL7DOC4T.js} +4 -4
  56. package/dist/{spans-VA2N5JX4.js → spans-VGUS5VVT.js} +4 -4
  57. package/dist/{src-PHVWXSHO.js → src-Z4SWZZTC.js} +3 -3
  58. package/dist/{token-AKUP2Q7O.js → token-RCKWGA5Y.js} +5 -5
  59. package/dist/{token-util-2MHFIMFV.js → token-util-SSDH7KHA.js} +5 -5
  60. package/dist/{typescript-GWQR45BP.js → typescript-MJFYBIS7.js} +3 -3
  61. package/dist/{v4-MJ7Z6RFC.js → v4-X3MR5FF4.js} +4 -4
  62. package/dist/{wrap-ansi-O7TR46WQ.js → wrap-ansi-GQYVQSCK.js} +5 -5
  63. package/dist/{yaml-VUB5VSYH.js → yaml-SGGZBW3K.js} +3 -3
  64. package/oclif.manifest.json +1 -1
  65. package/package.json +7 -7
  66. package/dist/chunk-TIXWC3AJ.js.map +0 -1
  67. package/dist/dist-T7YMQ4FI.js.map +0 -1
  68. /package/dist/{acorn-R44QJXGX.js.map → acorn-DGX7PYLV.js.map} +0 -0
  69. /package/dist/{angular-32M7AVGS.js.map → angular-R4NX53UH.js.map} +0 -0
  70. /package/dist/{api-WIV6M7TY.js.map → api-PUBF6KGO.js.map} +0 -0
  71. /package/dist/{babel-PFQW4XYW.js.map → babel-7RVI34KO.js.map} +0 -0
  72. /package/dist/{chunk-4T3WLZPG.js.map → chunk-2UIYBP3A.js.map} +0 -0
  73. /package/dist/{chunk-DJMTVLRU.js.map → chunk-5Q5V3TET.js.map} +0 -0
  74. /package/dist/{chunk-OZ4CSS7U.js.map → chunk-6FY2V2IK.js.map} +0 -0
  75. /package/dist/{chunk-IIZNQTMP.js.map → chunk-FOBDVZDC.js.map} +0 -0
  76. /package/dist/{chunk-ZDJ4PS2J.js.map → chunk-G3BZOYGH.js.map} +0 -0
  77. /package/dist/{chunk-VC5KDSHO.js.map → chunk-HIJTEOLS.js.map} +0 -0
  78. /package/dist/{chunk-DB3LEK4O.js.map → chunk-HL25LM4M.js.map} +0 -0
  79. /package/dist/{chunk-VC6MXN5M.js.map → chunk-JMVQQKJH.js.map} +0 -0
  80. /package/dist/{chunk-VJIYWOYI.js.map → chunk-JPPNFPS7.js.map} +0 -0
  81. /package/dist/{chunk-4ZEAMO2U.js.map → chunk-KCSBSTLV.js.map} +0 -0
  82. /package/dist/{chunk-6LFVTDU2.js.map → chunk-SAWXWFA5.js.map} +0 -0
  83. /package/dist/{chunk-TGCCW35O.js.map → chunk-TGRVOJ2E.js.map} +0 -0
  84. /package/dist/{chunk-EQFSCQQM.js.map → chunk-XB77S427.js.map} +0 -0
  85. /package/dist/{chunk-RPVWH5XI.js.map → chunk-XDZLYZIH.js.map} +0 -0
  86. /package/dist/{chunk-MEJXCYPE.js.map → chunk-XIUG55BY.js.map} +0 -0
  87. /package/dist/{chunk-D4566SJ7.js.map → chunk-YYWYPK75.js.map} +0 -0
  88. /package/dist/{chunk-LVBXHCNA.js.map → chunk-Z2REETG5.js.map} +0 -0
  89. /package/dist/{chunk-WEX5IXBC.js.map → chunk-ZWPASRGT.js.map} +0 -0
  90. /package/dist/{cli-truncate-L4JXF7K6.js.map → cli-truncate-4EMBJY7A.js.map} +0 -0
  91. /package/dist/{dd-trace-V65JTNHD.js.map → dd-trace-6GDHAGGU.js.map} +0 -0
  92. /package/dist/{dist-Q3R2FBE2.js.map → dist-5JXJ7LYZ.js.map} +0 -0
  93. /package/dist/{embedded-playwright-mcp-server-XVYGQCP2.js.map → embedded-playwright-mcp-server-QIV5UP2O.js.map} +0 -0
  94. /package/dist/{enquirer-YVBWN72T.js.map → enquirer-N2JRBZF7.js.map} +0 -0
  95. /package/dist/{estree-6PWHHM2H.js.map → estree-HCHNQOO2.js.map} +0 -0
  96. /package/dist/{flow-KCVOER5U.js.map → flow-UMJJW5UK.js.map} +0 -0
  97. /package/dist/{getMachineId-bsd-D5RAZQ2D.js.map → getMachineId-bsd-HYDQSXAS.js.map} +0 -0
  98. /package/dist/{getMachineId-darwin-BSFO7XMW.js.map → getMachineId-darwin-EFSF4DUT.js.map} +0 -0
  99. /package/dist/{getMachineId-linux-6NVJ5V5T.js.map → getMachineId-linux-WLTMPU7W.js.map} +0 -0
  100. /package/dist/{getMachineId-unsupported-4VOVSAF3.js.map → getMachineId-unsupported-2M2LW2NR.js.map} +0 -0
  101. /package/dist/{getMachineId-win-YUDPXOPQ.js.map → getMachineId-win-UNYCQSBF.js.map} +0 -0
  102. /package/dist/{glimmer-V64NM4J5.js.map → glimmer-XSXAY37I.js.map} +0 -0
  103. /package/dist/{graphql-B6AYKOKI.js.map → graphql-IH2EYV52.js.map} +0 -0
  104. /package/dist/{html-ZBVVO3ZX.js.map → html-23SNBE4X.js.map} +0 -0
  105. /package/dist/{http-L4BTSYOU.js.map → http-SBMHFWHF.js.map} +0 -0
  106. /package/dist/{jiti-R3YSBCRO.js.map → jiti-GRIYEDYH.js.map} +0 -0
  107. /package/dist/{log-update-KVOLYFCC.js.map → log-update-4GNKHCTM.js.map} +0 -0
  108. /package/dist/{markdown-REEFWBCX.js.map → markdown-V6KHVZDT.js.map} +0 -0
  109. /package/dist/{meriyah-T5IDFQVO.js.map → meriyah-CXWFY3WL.js.map} +0 -0
  110. /package/dist/{postcss-3EBJ7C2O.js.map → postcss-23O3XFEP.js.map} +0 -0
  111. /package/dist/{read-pkg-6Z3BVK5L.js.map → read-pkg-SL7DOC4T.js.map} +0 -0
  112. /package/dist/{spans-VA2N5JX4.js.map → spans-VGUS5VVT.js.map} +0 -0
  113. /package/dist/{src-PHVWXSHO.js.map → src-Z4SWZZTC.js.map} +0 -0
  114. /package/dist/{token-AKUP2Q7O.js.map → token-RCKWGA5Y.js.map} +0 -0
  115. /package/dist/{token-util-2MHFIMFV.js.map → token-util-SSDH7KHA.js.map} +0 -0
  116. /package/dist/{typescript-GWQR45BP.js.map → typescript-MJFYBIS7.js.map} +0 -0
  117. /package/dist/{v4-MJ7Z6RFC.js.map → v4-X3MR5FF4.js.map} +0 -0
  118. /package/dist/{wrap-ansi-O7TR46WQ.js.map → wrap-ansi-GQYVQSCK.js.map} +0 -0
  119. /package/dist/{yaml-VUB5VSYH.js.map → yaml-SGGZBW3K.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  if (typeof process === 'object' && process !== null &&
2
2
  process.env !== null && typeof process.env === 'object') {
3
3
  process.env.DD_GIT_REPOSITORY_URL = 'https://token@github.com/superblocksteam/superblocks.git';
4
- process.env.DD_GIT_COMMIT_SHA = '2ee59e9d024805e249f694ef52557d46e859a5f3';
4
+ process.env.DD_GIT_COMMIT_SHA = 'b65dbfb7f30ddd04acb93d48c2d7840cf91cafe4';
5
5
  }
6
6
  import { createRequire as $dd_createRequire } from 'module';
7
7
  import { fileURLToPath as $dd_fileURLToPath } from 'url';
@@ -13,7 +13,7 @@ globalThis.__dirname ??= $dd_dirname(globalThis.__filename);
13
13
  import {
14
14
  McpServer,
15
15
  StdioServerTransport
16
- } from "./chunk-EQFSCQQM.js";
16
+ } from "./chunk-XB77S427.js";
17
17
  import {
18
18
  CallToolResultSchema,
19
19
  ContentBlockSchema,
@@ -27,30 +27,37 @@ import {
27
27
  executeToolCall,
28
28
  runWithAuthContext,
29
29
  toolDefinitions
30
- } from "./chunk-TIXWC3AJ.js";
30
+ } from "./chunk-TWCRH5BC.js";
31
31
  import {
32
32
  external_exports
33
- } from "./chunk-DJMTVLRU.js";
34
- import "./chunk-VC6MXN5M.js";
33
+ } from "./chunk-5Q5V3TET.js";
34
+ import "./chunk-JMVQQKJH.js";
35
35
  import {
36
+ getDefaultPolicy,
37
+ import_shared,
36
38
  import_websocket,
39
+ initNodeTelemetry,
40
+ parseDeploymentType,
37
41
  require_dist
38
- } from "./chunk-EB6EWBNB.js";
39
- import "./chunk-4T3WLZPG.js";
40
- import "./chunk-D4566SJ7.js";
41
- import "./chunk-LVBXHCNA.js";
42
- import "./chunk-TGCCW35O.js";
43
- import "./chunk-DB3LEK4O.js";
44
- import "./chunk-WEX5IXBC.js";
42
+ } from "./chunk-GSEYYU3O.js";
43
+ import "./chunk-2UIYBP3A.js";
44
+ import "./chunk-YYWYPK75.js";
45
+ import "./chunk-Z2REETG5.js";
46
+ import "./chunk-TGRVOJ2E.js";
47
+ import "./chunk-HL25LM4M.js";
48
+ import "./chunk-ZWPASRGT.js";
45
49
  import {
50
+ SpanStatusCode,
51
+ context,
46
52
  init_esm,
47
- metrics
48
- } from "./chunk-VJIYWOYI.js";
53
+ metrics,
54
+ trace
55
+ } from "./chunk-JPPNFPS7.js";
49
56
  import {
50
57
  __require,
51
58
  __toESM,
52
59
  init_cjs_shims
53
- } from "./chunk-4ZEAMO2U.js";
60
+ } from "./chunk-KCSBSTLV.js";
54
61
 
55
62
  // ../../../gateway/dist/index.js
56
63
  init_cjs_shims();
@@ -232,7 +239,7 @@ function formatCaptureModeSummary(input) {
232
239
 
233
240
  // ../../../gateway/dist/capabilities/lifecycle.js
234
241
  init_cjs_shims();
235
- var import_shared2 = __toESM(require_dist());
242
+ var import_shared3 = __toESM(require_dist());
236
243
  import { randomUUID } from "node:crypto";
237
244
  import { readFile, realpath, stat } from "node:fs/promises";
238
245
  import path2 from "node:path";
@@ -437,7 +444,7 @@ function buildOpenablePreviewUrls(input) {
437
444
 
438
445
  // ../../../gateway/dist/server/client.js
439
446
  init_cjs_shims();
440
- var import_shared = __toESM(require_dist());
447
+ var import_shared2 = __toESM(require_dist());
441
448
 
442
449
  // ../../../gateway/dist/telemetry/metrics.js
443
450
  init_cjs_shims();
@@ -841,7 +848,7 @@ var HttpSuperblocksServerClient = class {
841
848
  }
842
849
  async uploadAttachment(input) {
843
850
  const mimeType = input.mimeType ?? "application/zip";
844
- const response = await (0, import_shared.uploadAttachmentToServerApi)({
851
+ const response = await (0, import_shared2.uploadAttachmentToServerApi)({
845
852
  applicationId: input.applicationId,
846
853
  authorization: `Bearer ${input.apiKey}`,
847
854
  baseUrl: this.baseUrl(),
@@ -888,10 +895,18 @@ var HttpSuperblocksServerClient = class {
888
895
  */
889
896
  async issueScopedToken(input) {
890
897
  const scope = input.scope ?? "apps:update";
891
- const body = {
892
- applicationId: input.applicationId,
893
- scope
894
- };
898
+ const body = { scope };
899
+ if (scope === "integrations:build") {
900
+ if (!input.integrationId?.trim()) {
901
+ throw new Error("integrations:build scoped tokens require an integrationId; the token authorizes exactly one integration");
902
+ }
903
+ body.integrationId = input.integrationId;
904
+ } else {
905
+ if (!input.applicationId?.trim()) {
906
+ throw new Error(`${scope} scoped tokens require an applicationId`);
907
+ }
908
+ body.applicationId = input.applicationId;
909
+ }
895
910
  if (scope === "apps:preview") {
896
911
  if (!input.commitId?.trim()) {
897
912
  throw new Error("apps:preview scoped tokens require a commitId so the viewer can load that commit");
@@ -1831,36 +1846,36 @@ async function captureModeOf(ctx) {
1831
1846
  });
1832
1847
  }
1833
1848
  function libraryCaptureInput(ctx, applicationId) {
1834
- const context = ctx.sessionPeer.libraryBrowserContext?.(applicationId);
1835
- if (!context) {
1849
+ const context2 = ctx.sessionPeer.libraryBrowserContext?.(applicationId);
1850
+ if (!context2) {
1836
1851
  return void 0;
1837
1852
  }
1838
- const auth = context.initData.devServerAuthorization;
1853
+ const auth = context2.initData.devServerAuthorization;
1839
1854
  if (!auth) {
1840
1855
  console.error("gateway live canvas skipped: missing_dev_server_authorization", { applicationId });
1841
1856
  return void 0;
1842
1857
  }
1843
1858
  return {
1844
1859
  bootstrapData: {
1845
- accessToken: context.bootstrapData.accessToken,
1846
- agents: context.bootstrapData.agents ?? [],
1847
- ...context.bootstrapData.agentUrls ? { agentUrls: context.bootstrapData.agentUrls } : {},
1848
- appId: context.bootstrapData.appId,
1849
- ...context.bootstrapData.featureFlags ? { featureFlags: context.bootstrapData.featureFlags } : {},
1850
- ...context.bootstrapData.orgId ? { orgId: context.bootstrapData.orgId } : {},
1851
- ...context.bootstrapData.profiles ? { profiles: context.bootstrapData.profiles } : {},
1852
- token: context.bootstrapData.token,
1853
- ...context.bootstrapData.userEmail ? { userEmail: context.bootstrapData.userEmail } : {},
1854
- userId: context.bootstrapData.userId,
1855
- ...context.bootstrapData.windowOriginUrl ? { windowOriginUrl: context.bootstrapData.windowOriginUrl } : {}
1860
+ accessToken: context2.bootstrapData.accessToken,
1861
+ agents: context2.bootstrapData.agents ?? [],
1862
+ ...context2.bootstrapData.agentUrls ? { agentUrls: context2.bootstrapData.agentUrls } : {},
1863
+ appId: context2.bootstrapData.appId,
1864
+ ...context2.bootstrapData.featureFlags ? { featureFlags: context2.bootstrapData.featureFlags } : {},
1865
+ ...context2.bootstrapData.orgId ? { orgId: context2.bootstrapData.orgId } : {},
1866
+ ...context2.bootstrapData.profiles ? { profiles: context2.bootstrapData.profiles } : {},
1867
+ token: context2.bootstrapData.token,
1868
+ ...context2.bootstrapData.userEmail ? { userEmail: context2.bootstrapData.userEmail } : {},
1869
+ userId: context2.bootstrapData.userId,
1870
+ ...context2.bootstrapData.windowOriginUrl ? { windowOriginUrl: context2.bootstrapData.windowOriginUrl } : {}
1856
1871
  },
1857
- iframeBaseUrl: context.iframeBaseUrl,
1872
+ iframeBaseUrl: context2.iframeBaseUrl,
1858
1873
  initData: {
1859
- appId: context.initData.appId,
1874
+ appId: context2.initData.appId,
1860
1875
  devServerAuthorization: auth,
1861
- peerId: context.initData.peerId,
1862
- ...context.initData.userId ? { userId: context.initData.userId } : {},
1863
- ...context.initData.windowOriginUrl ? { windowOriginUrl: context.initData.windowOriginUrl } : {}
1876
+ peerId: context2.initData.peerId,
1877
+ ...context2.initData.userId ? { userId: context2.initData.userId } : {},
1878
+ ...context2.initData.windowOriginUrl ? { windowOriginUrl: context2.initData.windowOriginUrl } : {}
1864
1879
  }
1865
1880
  };
1866
1881
  }
@@ -1984,13 +1999,15 @@ function defaultAppName(prompt) {
1984
1999
  async function ensurePrincipal(ctx) {
1985
2000
  const { principal } = ctx;
1986
2001
  if (principal.organizationId && principal.userId) {
2002
+ const resolved2 = {
2003
+ ...principal,
2004
+ organizationId: principal.organizationId,
2005
+ userId: principal.userId
2006
+ };
2007
+ ctx.onPrincipalResolved?.(resolved2);
1987
2008
  return {
1988
2009
  kind: "ok",
1989
- value: {
1990
- ...principal,
1991
- organizationId: principal.organizationId,
1992
- userId: principal.userId
1993
- }
2010
+ value: resolved2
1994
2011
  };
1995
2012
  }
1996
2013
  let validated;
@@ -2020,14 +2037,16 @@ async function ensurePrincipal(ctx) {
2020
2037
  message: "The Superblocks API rejected the credential issued for this caller."
2021
2038
  };
2022
2039
  }
2040
+ const resolved = {
2041
+ ...principal,
2042
+ email: validated.email,
2043
+ organizationId: validated.organizationId,
2044
+ userId: validated.userId
2045
+ };
2046
+ ctx.onPrincipalResolved?.(resolved);
2023
2047
  return {
2024
2048
  kind: "ok",
2025
- value: {
2026
- ...principal,
2027
- email: validated.email,
2028
- organizationId: validated.organizationId,
2029
- userId: validated.userId
2030
- }
2049
+ value: resolved
2031
2050
  };
2032
2051
  }
2033
2052
  async function nameWithClark(ctx, input) {
@@ -2220,7 +2239,7 @@ function turnSummary(turn) {
2220
2239
  return "Superblocks is still working, but only the editor can show it \u2014 open the edit URL";
2221
2240
  }
2222
2241
  if (turn.generationStatus === "live_edit_terminated") {
2223
- return "The Superblocks live-edit session terminated before anything was built \u2014 send the prompt again with edit_app";
2242
+ return turn.retryAction === "retry_import" ? "The Superblocks live-edit session terminated before anything was built \u2014 send the archive again with import_app" : "The Superblocks live-edit session terminated before anything was built \u2014 send the prompt again with edit_app";
2224
2243
  }
2225
2244
  if (turn.checkpointCommitId) {
2226
2245
  return `Application ready \u2014 checkpoint saved. ${NEXT_STEPS}`;
@@ -2346,6 +2365,7 @@ async function forwardClarkPrompt(ctx, input) {
2346
2365
  generationStatus: forward.generationStatus,
2347
2366
  ...forward.liveEditId ? { liveEditId: forward.liveEditId } : {},
2348
2367
  ...forward.recentRuns && forward.recentRuns.length > 0 ? { recentRuns: forward.recentRuns } : {},
2368
+ ...forward.retryAction ? { retryAction: forward.retryAction } : {},
2349
2369
  viewStatus: forward.viewStatus
2350
2370
  }
2351
2371
  };
@@ -2391,7 +2411,7 @@ function namingCreatedApplication(applicationId, capability, result) {
2391
2411
  return namingApplication(applicationId, result);
2392
2412
  }
2393
2413
  function retryIfReplayable(attachments) {
2394
- return attachments && attachments.length > 0 ? void 0 : { pendingAction: "retry_build" };
2414
+ return attachments && attachments.length > 0 ? { pendingAction: "retry_import" } : { pendingAction: "retry_build" };
2395
2415
  }
2396
2416
  function liveEditUnavailable(error, attachments) {
2397
2417
  return {
@@ -2412,7 +2432,8 @@ function rememberFailedStart(ctx, input) {
2412
2432
  organizationId: input.principal.organizationId,
2413
2433
  // Reaches the caller as the dead start's reply on its next poll, so it
2414
2434
  // has to stand on its own there rather than lean on this call's error.
2415
- reason: `The Superblocks live-edit session for application ${input.applicationId} never opened, so the prompt never reached Superblocks and nothing was built. Nothing is running for that application; send the same instruction again to retry it. (${cause})`,
2435
+ reason: input.reason ?? `The Superblocks live-edit session for application ${input.applicationId} never opened, so the prompt never reached Superblocks and nothing was built. Nothing is running for that application; send the same instruction again to retry it. (${cause})`,
2436
+ ...input.retryAction ? { retryAction: input.retryAction } : {},
2416
2437
  userId: input.principal.userId
2417
2438
  });
2418
2439
  } catch (error) {
@@ -2442,7 +2463,12 @@ async function promptNewApplication(ctx, args) {
2442
2463
  organizationId: principal.organizationId
2443
2464
  });
2444
2465
  } catch (error) {
2445
- rememberFailedStart(ctx, { applicationId, error, principal });
2466
+ rememberFailedStart(ctx, {
2467
+ applicationId,
2468
+ error,
2469
+ principal,
2470
+ ...args.attachments?.length ? { retryAction: "retry_import" } : {}
2471
+ });
2446
2472
  return liveEditUnavailable(error, args.attachments);
2447
2473
  }
2448
2474
  ctx.onProgress?.({
@@ -2637,7 +2663,7 @@ async function resolveImportArchive(input, searchDirs) {
2637
2663
  if (bytes.byteLength > IMPORT_ZIP_MAX_BYTES) {
2638
2664
  return tooLargeError(bytes.byteLength);
2639
2665
  }
2640
- const archiveType = (0, import_shared2.detectAttachmentArchiveType)({ fileName });
2666
+ const archiveType = (0, import_shared3.detectAttachmentArchiveType)({ fileName });
2641
2667
  if (archiveType === null) {
2642
2668
  return {
2643
2669
  kind: "error",
@@ -2679,14 +2705,15 @@ function normalizeImportSource(source) {
2679
2705
  }
2680
2706
  }
2681
2707
  async function importApp(ctx, input) {
2708
+ const resumedApplicationId = input.applicationId?.trim();
2682
2709
  const archiveResult = await resolveImportArchive(input, ctx.config.importSearchDirs);
2683
2710
  if (archiveResult.kind !== "ok") {
2684
- return archiveResult;
2711
+ return resumedApplicationId ? namingApplication(resumedApplicationId, archiveResult) : archiveResult;
2685
2712
  }
2686
2713
  const archive = archiveResult.value;
2687
2714
  const principalResult = await ensurePrincipal(ctx);
2688
2715
  if (principalResult.kind !== "ok") {
2689
- return principalResult;
2716
+ return resumedApplicationId ? namingApplication(resumedApplicationId, principalResult) : principalResult;
2690
2717
  }
2691
2718
  const principal = principalResult.value;
2692
2719
  const source = normalizeImportSource(input.source);
@@ -2697,23 +2724,26 @@ async function importApp(ctx, input) {
2697
2724
  });
2698
2725
  const explicitName = input.name?.trim();
2699
2726
  const name = explicitName || defaultAppName(migrationPrompt);
2700
- ctx.onProgress?.({
2701
- message: "Creating application for import",
2702
- type: "progress"
2703
- });
2704
- const created = await createApplicationForPrompt(ctx, {
2705
- apiKey: principal.apiKey,
2706
- name,
2707
- organizationId: principal.organizationId,
2708
- templateName: "app-fullstack"
2709
- });
2710
- if (created.kind !== "ok") {
2711
- return created;
2727
+ let applicationId = resumedApplicationId;
2728
+ if (!applicationId) {
2729
+ ctx.onProgress?.({
2730
+ message: "Creating application for import",
2731
+ type: "progress"
2732
+ });
2733
+ const created = await createApplicationForPrompt(ctx, {
2734
+ apiKey: principal.apiKey,
2735
+ name,
2736
+ organizationId: principal.organizationId,
2737
+ templateName: "app-fullstack"
2738
+ });
2739
+ if (created.kind !== "ok") {
2740
+ return created;
2741
+ }
2742
+ applicationId = created.value.id;
2712
2743
  }
2713
- const app = created.value;
2714
- await rememberApplication(ctx, principal, app.id);
2715
- return namingCreatedApplication(app.id, "import_app", await migrateArchiveIntoApplication(ctx, {
2716
- applicationId: app.id,
2744
+ await rememberApplication(ctx, principal, applicationId);
2745
+ const result = await migrateArchiveIntoApplication(ctx, {
2746
+ applicationId,
2717
2747
  archive,
2718
2748
  explicitName,
2719
2749
  input,
@@ -2721,7 +2751,8 @@ async function importApp(ctx, input) {
2721
2751
  name,
2722
2752
  principal,
2723
2753
  source
2724
- }));
2754
+ });
2755
+ return resumedApplicationId ? namingApplication(applicationId, result) : namingCreatedApplication(applicationId, "import_app", result);
2725
2756
  }
2726
2757
  async function migrateArchiveIntoApplication(ctx, args) {
2727
2758
  const { applicationId, archive, principal } = args;
@@ -2740,10 +2771,18 @@ async function migrateArchiveIntoApplication(ctx, args) {
2740
2771
  });
2741
2772
  } catch (error) {
2742
2773
  const message = error instanceof Error ? error.message : String(error);
2774
+ rememberFailedStart(ctx, {
2775
+ applicationId,
2776
+ error,
2777
+ principal,
2778
+ reason: `The archive for application ${applicationId} could not be uploaded, so the migration never started and nothing was built. Send the same archive again with import_app to retry it. (${message})`,
2779
+ retryAction: "retry_import"
2780
+ });
2743
2781
  return {
2744
2782
  kind: "error",
2745
2783
  code: "import_upload_failed",
2746
- message
2784
+ message,
2785
+ pendingAction: "retry_import"
2747
2786
  };
2748
2787
  }
2749
2788
  return promptNewApplication(ctx, {
@@ -2828,7 +2867,7 @@ async function checkAppProgress(ctx, input) {
2828
2867
  }
2829
2868
  const applicationId = resolved.value;
2830
2869
  if (ctx.signal?.aborted) {
2831
- return cancelled("check_app_progress");
2870
+ return namingApplication(applicationId, cancelled("check_app_progress"));
2832
2871
  }
2833
2872
  const cursorKey2 = cursorKeyFor(ctx, principal, applicationId);
2834
2873
  const stored = cursorKey2 ? await ctx.progressCursors?.getCursor(cursorKey2) : void 0;
@@ -2840,7 +2879,7 @@ async function checkAppProgress(ctx, input) {
2840
2879
  waitMs: hostCallBudgetMs(ctx, ctx.config.clarkProgressWaitMs)
2841
2880
  });
2842
2881
  if (ctx.signal?.aborted) {
2843
- return cancelled("check_app_progress");
2882
+ return namingApplication(applicationId, cancelled("check_app_progress"));
2844
2883
  }
2845
2884
  const snapshot = await readSnapshot(ctx, {
2846
2885
  applicationId,
@@ -2914,6 +2953,7 @@ async function checkAppProgress(ctx, input) {
2914
2953
  reply: update.reply,
2915
2954
  ...update.decision ? { decision: update.decision } : {},
2916
2955
  generationStatus: update.generationStatus,
2956
+ ...update.retryAction && emptyTurnStatus(update.generationStatus) ? { pendingAction: update.retryAction } : {},
2917
2957
  status,
2918
2958
  viewStatus: update.viewStatus
2919
2959
  }
@@ -3335,7 +3375,11 @@ function localUnbuiltReason(turn, pending) {
3335
3375
  return void 0;
3336
3376
  }
3337
3377
  const status = emptyTurnStatus(turn.generationStatus);
3338
- return status ? { kind: "empty_turn", status } : void 0;
3378
+ return status ? {
3379
+ kind: "empty_turn",
3380
+ retryAction: turn.retryAction ?? "retry_build",
3381
+ status
3382
+ } : void 0;
3339
3383
  }
3340
3384
  async function persistedUnbuiltReason(ctx, principal, applicationId) {
3341
3385
  let snapshot;
@@ -3378,6 +3422,8 @@ function persistedTurnEnd(status) {
3378
3422
  // plain question and cannot be approved.
3379
3423
  case "needs_decision":
3380
3424
  return { kind: "awaiting_decision" };
3425
+ // The stream never recorded whether the prompt carried an archive, so
3426
+ // this path cannot pick retry_build vs retry_import. Omit rather than guess.
3381
3427
  case "live_edit_terminated":
3382
3428
  return { kind: "empty_turn", status };
3383
3429
  // A `cancelled` in the tail may still have a real app behind it: the
@@ -3436,7 +3482,11 @@ async function unbuiltApp(ctx, principal, applicationId) {
3436
3482
  if (reason.kind === "empty_turn") {
3437
3483
  return {
3438
3484
  kind: "ok",
3439
- value: { ...app, pendingAction: "retry_build", status: reason.status }
3485
+ value: {
3486
+ ...app,
3487
+ ...reason.retryAction ? { pendingAction: reason.retryAction } : {},
3488
+ status: reason.status
3489
+ }
3440
3490
  };
3441
3491
  }
3442
3492
  return {
@@ -3538,7 +3588,7 @@ async function waitForBuild(ctx, input) {
3538
3588
  let started = false;
3539
3589
  for (; ; ) {
3540
3590
  if (ctx.signal?.aborted) {
3541
- return cancelled("get_app");
3591
+ return namingApplication(input.applicationId, cancelled("get_app"));
3542
3592
  }
3543
3593
  if (nowMs(ctx) >= deadline) {
3544
3594
  return { kind: "ok", value: { built: false } };
@@ -4192,7 +4242,7 @@ async function createStores() {
4192
4242
  // ../../../gateway/dist/sabs/websocket-session-peer.js
4193
4243
  init_cjs_shims();
4194
4244
  import { randomUUID as randomUUID3 } from "node:crypto";
4195
- var import_shared5 = __toESM(require_dist());
4245
+ var import_shared6 = __toESM(require_dist());
4196
4246
 
4197
4247
  // ../../../gateway/dist/agents/resolve-orchestrator-url.js
4198
4248
  init_cjs_shims();
@@ -4513,15 +4563,15 @@ var HttpOrchestratorClient = class {
4513
4563
 
4514
4564
  // ../../../gateway/dist/sabs/browser-context.js
4515
4565
  init_cjs_shims();
4516
- var import_shared3 = __toESM(require_dist());
4566
+ var import_shared4 = __toESM(require_dist());
4517
4567
  function toProfile(row) {
4518
- return new import_shared3.Profile({
4568
+ return new import_shared4.Profile({
4519
4569
  allowedInEditor: row.allowedInEditor,
4520
4570
  description: "",
4521
4571
  displayName: row.displayName ?? row.key,
4522
4572
  id: row.id ?? row.key,
4523
4573
  key: row.key,
4524
- type: import_shared3.ProfileType.RESERVED
4574
+ type: import_shared4.ProfileType.RESERVED
4525
4575
  });
4526
4576
  }
4527
4577
  function selectProfiles(input) {
@@ -4584,7 +4634,7 @@ function buildBrowserContext(input) {
4584
4634
 
4585
4635
  // ../../../gateway/dist/sabs/editor-client-methods.js
4586
4636
  init_cjs_shims();
4587
- var import_shared4 = __toESM(require_dist());
4637
+ var import_shared5 = __toESM(require_dist());
4588
4638
 
4589
4639
  // ../../../gateway/dist/integrations/map.js
4590
4640
  init_cjs_shims();
@@ -4739,7 +4789,7 @@ function sanitizeAgentFacingValue(value) {
4739
4789
  }
4740
4790
 
4741
4791
  // ../../../gateway/dist/sabs/editor-client-methods.js
4742
- var ADMIN_MCP_SETUP_MESSAGE = "Integrations CRUD is available on this Superblocks MCP via create_integration, update_integration, and list_integrations (same connector as start_app). Use those Admin tools, then continue with edit_app. The headless editor session cannot open the Integrations UI.";
4792
+ var ADMIN_MCP_SETUP_MESSAGE = "Integrations CRUD is available on this Superblocks MCP via get_integration_config_schema, create_integration, update_integration, and list_integrations (same connector as start_app). Call get_integration_config_schema before create_integration. Use those Admin tools, then continue with edit_app. The headless editor session cannot open the Integrations UI.";
4743
4793
  var HEADLESS_AUTO_APPROVED_TOOLS = /* @__PURE__ */ new Set([
4744
4794
  "build_deleteFile",
4745
4795
  "build_installPackages",
@@ -4825,27 +4875,27 @@ function clarifySdkExecutionErrorMessage(message) {
4825
4875
  }
4826
4876
  return sanitizeAgentFacingText(clarified);
4827
4877
  }
4828
- async function executeRequestToIntegrationViaOrchestrator(context, payload) {
4878
+ async function executeRequestToIntegrationViaOrchestrator(context2, payload) {
4829
4879
  let pluginId = payload.integrationHint?.type;
4830
4880
  let integrationName = payload.integrationHint?.displayName ?? payload.integrationHint?.name ?? "Integration";
4831
4881
  if (!pluginId) {
4832
4882
  let row;
4833
4883
  try {
4834
- row = await context.server.getIntegration({
4835
- apiKey: context.apiKey,
4884
+ row = await context2.server.getIntegration({
4885
+ apiKey: context2.apiKey,
4836
4886
  integrationId: payload.integrationId
4837
4887
  });
4838
4888
  if (!row) {
4839
- const rows = await context.server.getSupersetIntegrations({
4840
- apiKey: context.apiKey,
4841
- applicationId: context.applicationId,
4842
- organizationId: context.organizationId
4889
+ const rows = await context2.server.getSupersetIntegrations({
4890
+ apiKey: context2.apiKey,
4891
+ applicationId: context2.applicationId,
4892
+ organizationId: context2.organizationId
4843
4893
  });
4844
4894
  row = rows.find((candidate) => candidate.id === payload.integrationId);
4845
4895
  }
4846
4896
  } catch (error) {
4847
4897
  console.warn("gateway failed to resolve integration for execute", {
4848
- applicationId: context.applicationId,
4898
+ applicationId: context2.applicationId,
4849
4899
  integrationId: payload.integrationId,
4850
4900
  message: error instanceof Error ? error.message : String(error)
4851
4901
  });
@@ -4858,7 +4908,7 @@ async function executeRequestToIntegrationViaOrchestrator(context, payload) {
4858
4908
  pluginId = row.pluginId;
4859
4909
  integrationName = row.name || integrationName;
4860
4910
  }
4861
- const pluginIdForStep = (0, import_shared4.getBasePluginId)(pluginId);
4911
+ const pluginIdForStep = (0, import_shared5.getBasePluginId)(pluginId);
4862
4912
  const now = (/* @__PURE__ */ new Date()).toISOString();
4863
4913
  const inlineApiId = `ai-inline-${payload.integrationId}-${Date.now()}`;
4864
4914
  const definition = {
@@ -4874,14 +4924,14 @@ async function executeRequestToIntegrationViaOrchestrator(context, payload) {
4874
4924
  metadata: {
4875
4925
  id: inlineApiId,
4876
4926
  name: `${integrationName} AI Query`,
4877
- organization: context.organizationId,
4927
+ organization: context2.organizationId,
4878
4928
  timestamps: { created: now, updated: now }
4879
4929
  },
4880
4930
  trigger: { application: {} }
4881
4931
  };
4882
4932
  try {
4883
- const result = await context.orchestrator.executeV2Api({
4884
- apiKey: context.apiKey,
4933
+ const result = await context2.orchestrator.executeV2Api({
4934
+ apiKey: context2.apiKey,
4885
4935
  body: {
4886
4936
  definition: { api: definition },
4887
4937
  inputs: {},
@@ -4892,10 +4942,10 @@ async function executeRequestToIntegrationViaOrchestrator(context, payload) {
4892
4942
  isAiTriggered: true,
4893
4943
  suppressTracking: true
4894
4944
  },
4895
- ...context.profileKey ? { profile: { name: context.profileKey } } : {}
4945
+ ...context2.profileKey ? { profile: { name: context2.profileKey } } : {}
4896
4946
  },
4897
- profileKey: context.profileKey,
4898
- scopedToken: context.sessionToken
4947
+ profileKey: context2.profileKey,
4948
+ scopedToken: context2.sessionToken
4899
4949
  });
4900
4950
  if (result && typeof result === "object" && "systemError" in result) {
4901
4951
  const systemError = String(result.systemError ?? "Integration execution failed");
@@ -4931,11 +4981,11 @@ async function executeRequestToIntegrationViaOrchestrator(context, payload) {
4931
4981
  return { error: clarifySdkExecutionErrorMessage(message) };
4932
4982
  }
4933
4983
  }
4934
- async function loadIntegrationsForPrompt(context) {
4935
- const rows = await context.server.getSupersetIntegrations({
4936
- apiKey: context.apiKey,
4937
- applicationId: context.applicationId,
4938
- organizationId: context.organizationId
4984
+ async function loadIntegrationsForPrompt(context2) {
4985
+ const rows = await context2.server.getSupersetIntegrations({
4986
+ apiKey: context2.apiKey,
4987
+ applicationId: context2.applicationId,
4988
+ organizationId: context2.organizationId
4939
4989
  });
4940
4990
  return listIntegrationsForClark(rows);
4941
4991
  }
@@ -5080,10 +5130,9 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5080
5130
  ],
5081
5131
  updateApiInputs: ack,
5082
5132
  updateScope: ack,
5083
- // No browser tab means no viewport to photograph. The flag matters more
5084
- // than the message: it tells the ai-service this was a refusal, not a
5085
- // failed capture, so Clark can fall back to the sandbox's own browser
5086
- // instead of reporting that it cannot see the app it just built.
5133
+ // No browser tab means no viewport to photograph. viewportUnavailable
5134
+ // marks this as a refusal, not a failed capture. The screenshot tool
5135
+ // does not read that flag; MCP turns omit the tool via disabledTools.
5087
5136
  aiCaptureScreenshot: [
5088
5137
  async () => ({
5089
5138
  error: "the headless gateway session has no browser viewport",
@@ -5095,13 +5144,13 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5095
5144
  aiDeleteIntegration: setupUnavailable,
5096
5145
  aiExecuteRequestToIntegration: [
5097
5146
  async (payload) => {
5098
- const context = deps?.getContext();
5099
- if (!context) {
5147
+ const context2 = deps?.getContext();
5148
+ if (!context2) {
5100
5149
  return {
5101
5150
  error: "the headless gateway session cannot execute integration requests without an active prompt session"
5102
5151
  };
5103
5152
  }
5104
- const result = await executeRequestToIntegrationViaOrchestrator(context, payload);
5153
+ const result = await executeRequestToIntegrationViaOrchestrator(context2, payload);
5105
5154
  const name = payload.integrationHint?.name || payload.integrationId || "integration";
5106
5155
  deps?.onToolRun?.({
5107
5156
  detail: result,
@@ -5114,8 +5163,8 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5114
5163
  ],
5115
5164
  aiExecuteSdkApi: [
5116
5165
  async (payload) => {
5117
- const context = deps?.getContext();
5118
- if (!context) {
5166
+ const context2 = deps?.getContext();
5167
+ if (!context2) {
5119
5168
  throw missingSessionError("execute SDK APIs");
5120
5169
  }
5121
5170
  if (!payload.entryPoint) {
@@ -5135,7 +5184,7 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5135
5184
  return missing;
5136
5185
  }
5137
5186
  try {
5138
- const inSync = await context.waitUntilFilesSynced();
5187
+ const inSync = await context2.waitUntilFilesSynced();
5139
5188
  if (!inSync) {
5140
5189
  const syncing = {
5141
5190
  success: false,
@@ -5152,15 +5201,15 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5152
5201
  });
5153
5202
  return syncing;
5154
5203
  }
5155
- const response = await context.orchestrator.executeSdkApiV3({
5156
- apiKey: context.apiKey,
5157
- applicationId: context.applicationId,
5158
- branchName: context.branchName,
5204
+ const response = await context2.orchestrator.executeSdkApiV3({
5205
+ apiKey: context2.apiKey,
5206
+ applicationId: context2.applicationId,
5207
+ branchName: context2.branchName,
5159
5208
  entryPoint: payload.entryPoint,
5160
5209
  exportName: payload.exportName,
5161
5210
  inputs: payload.input ?? {},
5162
- profileKey: context.profileKey,
5163
- scopedToken: context.sessionToken
5211
+ profileKey: context2.profileKey,
5212
+ scopedToken: context2.sessionToken
5164
5213
  });
5165
5214
  const mapped = mapSdkExecutionResponse(response);
5166
5215
  deps?.onToolRun?.({
@@ -5190,8 +5239,8 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5190
5239
  ],
5191
5240
  aiExecuteV2Api: [
5192
5241
  async (payload) => {
5193
- const context = deps?.getContext();
5194
- if (!context) {
5242
+ const context2 = deps?.getContext();
5243
+ if (!context2) {
5195
5244
  throw missingSessionError("execute V2 APIs");
5196
5245
  }
5197
5246
  if (payload.api.type === "fetch") {
@@ -5204,14 +5253,14 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5204
5253
  ...payload.api.definition,
5205
5254
  metadata: {
5206
5255
  ...payload.api.definition.metadata ?? {},
5207
- organization: context.organizationId,
5256
+ organization: context2.organizationId,
5208
5257
  timestamps: { created: now, updated: now }
5209
5258
  },
5210
5259
  trigger: { application: {} }
5211
5260
  };
5212
5261
  try {
5213
- const result = await context.orchestrator.executeV2Api({
5214
- apiKey: context.apiKey,
5262
+ const result = await context2.orchestrator.executeV2Api({
5263
+ apiKey: context2.apiKey,
5215
5264
  body: {
5216
5265
  definition: { api: definition },
5217
5266
  inputs: payload.inputs ?? {},
@@ -5222,10 +5271,10 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5222
5271
  isAiTriggered: true,
5223
5272
  suppressTracking: true
5224
5273
  },
5225
- ...context.profileKey ? { profile: { name: context.profileKey } } : {}
5274
+ ...context2.profileKey ? { profile: { name: context2.profileKey } } : {}
5226
5275
  },
5227
- profileKey: context.profileKey,
5228
- scopedToken: context.sessionToken
5276
+ profileKey: context2.profileKey,
5277
+ scopedToken: context2.sessionToken
5229
5278
  });
5230
5279
  if (result && typeof result === "object" && "systemError" in result) {
5231
5280
  return result;
@@ -5247,27 +5296,27 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5247
5296
  ],
5248
5297
  aiGetIntegration: [
5249
5298
  async (payload) => {
5250
- const context = deps?.getContext();
5251
- if (!context) {
5299
+ const context2 = deps?.getContext();
5300
+ if (!context2) {
5252
5301
  throw missingSessionError("provide integration metadata");
5253
5302
  }
5254
5303
  let row;
5255
5304
  try {
5256
- row = await context.server.getIntegration({
5257
- apiKey: context.apiKey,
5305
+ row = await context2.server.getIntegration({
5306
+ apiKey: context2.apiKey,
5258
5307
  integrationId: payload.integrationId
5259
5308
  });
5260
5309
  if (!row) {
5261
- const rows = await context.server.getSupersetIntegrations({
5262
- apiKey: context.apiKey,
5263
- applicationId: context.applicationId,
5264
- organizationId: context.organizationId
5310
+ const rows = await context2.server.getSupersetIntegrations({
5311
+ apiKey: context2.apiKey,
5312
+ applicationId: context2.applicationId,
5313
+ organizationId: context2.organizationId
5265
5314
  });
5266
5315
  row = rows.find((candidate) => candidate.id === payload.integrationId);
5267
5316
  }
5268
5317
  } catch (error) {
5269
5318
  console.warn("gateway failed to load integration for Clark", {
5270
- applicationId: context.applicationId,
5319
+ applicationId: context2.applicationId,
5271
5320
  integrationId: payload.integrationId,
5272
5321
  message: error instanceof Error ? error.message : String(error)
5273
5322
  });
@@ -5283,11 +5332,11 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5283
5332
  }
5284
5333
  let metadata = {};
5285
5334
  try {
5286
- metadata = await context.orchestrator.getMetadata({
5287
- apiKey: context.apiKey,
5335
+ metadata = await context2.orchestrator.getMetadata({
5336
+ apiKey: context2.apiKey,
5288
5337
  integrationId: payload.integrationId,
5289
- profileKey: context.profileKey,
5290
- scopedToken: context.sessionToken
5338
+ profileKey: context2.profileKey,
5339
+ scopedToken: context2.sessionToken
5291
5340
  });
5292
5341
  } catch {
5293
5342
  metadata = {};
@@ -5309,15 +5358,15 @@ function createEditorClientMethods(getListener, onInbound, deps) {
5309
5358
  ],
5310
5359
  aiGetIntegrations: [
5311
5360
  async () => {
5312
- const context = deps?.getContext();
5313
- if (!context) {
5361
+ const context2 = deps?.getContext();
5362
+ if (!context2) {
5314
5363
  return [];
5315
5364
  }
5316
5365
  try {
5317
- return await loadIntegrationsForPrompt(context);
5366
+ return await loadIntegrationsForPrompt(context2);
5318
5367
  } catch (error) {
5319
5368
  console.warn("gateway failed to list integrations for Clark", {
5320
- applicationId: context.applicationId,
5369
+ applicationId: context2.applicationId,
5321
5370
  message: error instanceof Error ? error.message : String(error)
5322
5371
  });
5323
5372
  return [];
@@ -5418,6 +5467,7 @@ function truncate(text, max = RECENT_TOOL_RUN_SUMMARY_MAX) {
5418
5467
  var GENERATE_METHOD = "editor.aiGenerateWithQueue";
5419
5468
  var ACCEPT_DRAFT_METHOD = "editor.aiAcceptDraft";
5420
5469
  var RELOAD_CHAT_METHOD = "editor.aiChatGetMessages";
5470
+ var RELEASE_TURN_LOCK_METHOD = "editor.releaseTurnLock";
5421
5471
  var RESPOND_TOOL_PERMISSION_METHOD = "editor.aiRespondToToolPermission";
5422
5472
  var PING_METHOD = "editor.ping";
5423
5473
  var DEFAULT_TIMEOUT_MS3 = 12e4;
@@ -5759,6 +5809,7 @@ var WebSocketSessionPeer = class {
5759
5809
  this.failedStarts.set(input, {
5760
5810
  generationStatus: "live_edit_terminated",
5761
5811
  reply: input.reason,
5812
+ ...input.retryAction ? { retryAction: input.retryAction } : {},
5762
5813
  // Nothing ran, so nothing is viewable. Reporting "ready" here is how a
5763
5814
  // caller comes to show the untouched starter template as the app.
5764
5815
  viewStatus: "unknown"
@@ -5791,7 +5842,11 @@ var WebSocketSessionPeer = class {
5791
5842
  }
5792
5843
  const failed = this.failedStarts.get(input);
5793
5844
  if (failed) {
5794
- return { generationStatus: failed.generationStatus, phase: "finished" };
5845
+ return {
5846
+ generationStatus: failed.generationStatus,
5847
+ phase: "finished",
5848
+ ...failed.retryAction ? { retryAction: failed.retryAction } : {}
5849
+ };
5795
5850
  }
5796
5851
  if (!turn?.finished) {
5797
5852
  return void 0;
@@ -5799,7 +5854,8 @@ var WebSocketSessionPeer = class {
5799
5854
  return {
5800
5855
  ...turn.finished.checkpointCommitId ? { checkpointCommitId: turn.finished.checkpointCommitId } : {},
5801
5856
  generationStatus: turn.finished.generationStatus,
5802
- phase: "finished"
5857
+ phase: "finished",
5858
+ ...turn.retryAction ? { retryAction: turn.retryAction } : {}
5803
5859
  };
5804
5860
  }
5805
5861
  clearPendingPlan(applicationId) {
@@ -5945,6 +6001,7 @@ var WebSocketSessionPeer = class {
5945
6001
  normalized: void 0,
5946
6002
  recentRuns: [],
5947
6003
  reconnects: 0,
6004
+ ...input.attachments?.length ? { retryAction: "retry_import" } : {},
5948
6005
  startedAt: Date.now(),
5949
6006
  turnId: randomUUID3(),
5950
6007
  unsubscribe: () => void 0,
@@ -6005,6 +6062,7 @@ var WebSocketSessionPeer = class {
6005
6062
  jwt: input.sessionToken,
6006
6063
  llmConfig: {
6007
6064
  coreModel: this.options.coreModel ?? DEFAULT_LLM.coreModel,
6065
+ disabledTools: ["build_captureScreenshot", "build_navigatePreview"],
6008
6066
  // The ai-service gates Clark's testing tools on this flag *and* a
6009
6067
  // browser context, so the two travel together or not at all.
6010
6068
  ...browserContext ? { flags: { isTestingEnabled: true } } : {},
@@ -6110,6 +6168,7 @@ var WebSocketSessionPeer = class {
6110
6168
  elapsedMs,
6111
6169
  status: "finished",
6112
6170
  ...turn.finished,
6171
+ ...turn.retryAction ? { retryAction: turn.retryAction } : {},
6113
6172
  ...recentRuns ? { recentRuns } : {}
6114
6173
  };
6115
6174
  }
@@ -6250,6 +6309,15 @@ var WebSocketSessionPeer = class {
6250
6309
  collector.dispose();
6251
6310
  const stillMapped = this.turns.get(input.applicationId) === turn;
6252
6311
  if (stillMapped) {
6312
+ try {
6313
+ await turn.held.client.requestWithTracing(RELEASE_TURN_LOCK_METHOD, this.turnCorrelator(turn.turnId), {}, `Bearer ${input.sessionToken}`);
6314
+ } catch (error) {
6315
+ console.warn("gateway could not release the live-edit turn lock", {
6316
+ applicationId: input.applicationId,
6317
+ message: describeSocketError(error),
6318
+ turnId: turn.turnId
6319
+ });
6320
+ }
6253
6321
  if (turn.finished?.generationStatus === "needs_decision") {
6254
6322
  this.armIdle(turn.held);
6255
6323
  } else {
@@ -6666,7 +6734,7 @@ var WebSocketSessionPeer = class {
6666
6734
  const heldRef = {
6667
6735
  current: void 0
6668
6736
  };
6669
- const socket = new import_shared5.ISocket(ws, createEditorClientMethods(() => {
6737
+ const socket = new import_shared6.ISocket(ws, createEditorClientMethods(() => {
6670
6738
  const listeners = heldRef.current?.listeners;
6671
6739
  if (!listeners || listeners.size === 0) {
6672
6740
  return void 0;
@@ -6743,7 +6811,7 @@ var WebSocketSessionPeer = class {
6743
6811
  noResponseTimeoutInSeconds: (this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS3) / 1e3
6744
6812
  }
6745
6813
  });
6746
- const client = (0, import_shared5.createISocketClient)(socket);
6814
+ const client = (0, import_shared6.createISocketClient)(socket);
6747
6815
  const heartbeat = this.buildHeartbeat(heldRef);
6748
6816
  const held = {
6749
6817
  applicationId: input.applicationId,
@@ -6779,7 +6847,7 @@ var WebSocketSessionPeer = class {
6779
6847
  * who to tell.
6780
6848
  */
6781
6849
  buildHeartbeat(heldRef) {
6782
- return new import_shared5.SocketHeartbeat({
6850
+ return new import_shared6.SocketHeartbeat({
6783
6851
  beat: async () => {
6784
6852
  const held = heldRef.current;
6785
6853
  if (!held?.sessionToken) {
@@ -7306,6 +7374,233 @@ var WebSocketSessionPeer = class {
7306
7374
  }
7307
7375
  };
7308
7376
 
7377
+ // ../../../gateway/dist/telemetry/runtime.js
7378
+ init_cjs_shims();
7379
+
7380
+ // ../../../gateway/dist/telemetry/mcp-client.js
7381
+ init_cjs_shims();
7382
+ init_esm();
7383
+ function bounded(value, maxLength) {
7384
+ return value.slice(0, maxLength);
7385
+ }
7386
+ function stringProperty(value, key2) {
7387
+ if (typeof value !== "object" || value === null || !(key2 in value)) {
7388
+ return void 0;
7389
+ }
7390
+ const property = Reflect.get(value, key2);
7391
+ return typeof property === "string" ? property : void 0;
7392
+ }
7393
+ var McpClientTelemetry = class {
7394
+ tracer;
7395
+ ended = false;
7396
+ hadError = false;
7397
+ organizationId;
7398
+ sessionContext;
7399
+ sessionSpan;
7400
+ constructor(tracer) {
7401
+ this.tracer = tracer;
7402
+ this.sessionSpan = tracer.startSpan("gen_ai.request", {
7403
+ attributes: {
7404
+ "gen_ai.operation.name": "invoke_agent"
7405
+ }
7406
+ });
7407
+ this.sessionContext = trace.setSpan(context.active(), this.sessionSpan);
7408
+ }
7409
+ setOrganizationId(organizationId) {
7410
+ this.organizationId = organizationId;
7411
+ this.sessionSpan.setAttribute("organization.id", organizationId);
7412
+ }
7413
+ async runTool(call, operation) {
7414
+ const attributes = {
7415
+ "gen_ai.operation.name": "execute_tool",
7416
+ ...call.client ? {
7417
+ "mcp.client.name": bounded(call.client.name, 80),
7418
+ ...call.client.version ? {
7419
+ "mcp.client.version": bounded(call.client.version, 40)
7420
+ } : {}
7421
+ } : {},
7422
+ ...this.organizationId ? { "organization.id": this.organizationId } : {},
7423
+ "tool.name": bounded(call.toolName, 80)
7424
+ };
7425
+ if (call.client) {
7426
+ this.sessionSpan.setAttributes({
7427
+ "mcp.client.name": bounded(call.client.name, 80),
7428
+ ...call.client.version ? { "mcp.client.version": bounded(call.client.version, 40) } : {}
7429
+ });
7430
+ }
7431
+ let span;
7432
+ try {
7433
+ span = this.tracer.startSpan("gen_ai.tool_call", { attributes }, this.sessionContext);
7434
+ } catch {
7435
+ return operation();
7436
+ }
7437
+ const startedAt = Date.now();
7438
+ try {
7439
+ const result = await context.with(trace.setSpan(this.sessionContext, span), operation);
7440
+ span.setAttribute("tool.duration_ms", Date.now() - startedAt);
7441
+ if (this.organizationId) {
7442
+ span.setAttribute("organization.id", this.organizationId);
7443
+ }
7444
+ if (result.kind === "error") {
7445
+ this.hadError = true;
7446
+ span.setAttributes({
7447
+ ...result.applicationId ? { "application.id": result.applicationId } : {},
7448
+ "mcp.error.code": bounded(result.code, 80),
7449
+ "tool.error_category": result.code === "cancelled" ? "timeout" : "execution_error",
7450
+ "tool.status": "error"
7451
+ });
7452
+ span.setStatus({ code: SpanStatusCode.ERROR });
7453
+ } else if (result.kind === "auth_required") {
7454
+ this.hadError = true;
7455
+ span.setAttributes({
7456
+ "mcp.result.status": "auth_required",
7457
+ "tool.error_category": "permission_denied",
7458
+ "tool.status": "error"
7459
+ });
7460
+ } else {
7461
+ const applicationId = stringProperty(result.value, "applicationId");
7462
+ const resultStatus = stringProperty(result.value, "status");
7463
+ span.setAttributes({
7464
+ ...applicationId ? { "application.id": applicationId } : {},
7465
+ ...resultStatus ? { "mcp.result.status": bounded(resultStatus, 80) } : {},
7466
+ "tool.error_category": "none",
7467
+ "tool.status": "success"
7468
+ });
7469
+ }
7470
+ return result;
7471
+ } catch (error) {
7472
+ this.hadError = true;
7473
+ span.setAttributes({
7474
+ "tool.duration_ms": Date.now() - startedAt,
7475
+ "tool.error_category": "execution_error",
7476
+ "tool.status": "error"
7477
+ });
7478
+ span.setStatus({ code: SpanStatusCode.ERROR });
7479
+ throw error;
7480
+ } finally {
7481
+ span.end();
7482
+ }
7483
+ }
7484
+ endSession() {
7485
+ if (this.ended) {
7486
+ return;
7487
+ }
7488
+ this.ended = true;
7489
+ this.sessionSpan.setAttribute("gen_ai.request.status", this.hadError ? "error" : "success");
7490
+ this.sessionSpan.end();
7491
+ }
7492
+ };
7493
+
7494
+ // ../../../gateway/dist/telemetry/runtime.js
7495
+ var TELEMETRY_SHUTDOWN_MS = 2e3;
7496
+ function logToStderr(first, message) {
7497
+ if (message === void 0) {
7498
+ console.error(first);
7499
+ return;
7500
+ }
7501
+ console.error(first, message);
7502
+ }
7503
+ var stderrLogger = {
7504
+ error: logToStderr,
7505
+ info: logToStderr,
7506
+ warn: logToStderr
7507
+ };
7508
+ function telemetryBaseUrl(serverUrl) {
7509
+ try {
7510
+ const url = new URL(serverUrl);
7511
+ url.hash = "";
7512
+ url.pathname = `${url.pathname.replace(/\/$/u, "")}/api`;
7513
+ url.search = "";
7514
+ return url.toString().replace(/\/$/u, "");
7515
+ } catch {
7516
+ console.error("gateway telemetry skipped: server URL is not parseable");
7517
+ return void 0;
7518
+ }
7519
+ }
7520
+ function environmentName(config) {
7521
+ if (config.deploymentEnvironmentName !== "unknown") {
7522
+ return config.deploymentEnvironmentName;
7523
+ }
7524
+ try {
7525
+ return environmentFromHostname(new URL(config.serverUrl).hostname);
7526
+ } catch {
7527
+ return "unknown";
7528
+ }
7529
+ }
7530
+ function environmentFromHostname(hostname) {
7531
+ if (hostname.match(/^app\.superblocks(?:hq)?\.com$/u)) {
7532
+ return "prod";
7533
+ }
7534
+ if (hostname.match(/^eu\.superblocks(?:hq)?\.com$/u)) {
7535
+ return "prod-eu";
7536
+ }
7537
+ if (hostname.match(/^staging\.superblocks(?:hq)?\.com$/u)) {
7538
+ return "staging";
7539
+ }
7540
+ if (hostname.match(/^dev\.superblocks(?:hq)?\.com$/u)) {
7541
+ return "dev";
7542
+ }
7543
+ if (hostname.match(/^pr-[0-9]+\.superblocks(?:hq)?\.dev$/u)) {
7544
+ return "ephemeral";
7545
+ }
7546
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
7547
+ return "local";
7548
+ }
7549
+ return "other";
7550
+ }
7551
+ function deploymentTypeFor(config) {
7552
+ if (config.localAgentMode) {
7553
+ return import_shared.DeploymentTypeEnum.CLOUD_PREM;
7554
+ }
7555
+ try {
7556
+ return parseDeploymentType(process.env.SUPERBLOCKS_DEPLOYMENT_TYPE);
7557
+ } catch {
7558
+ return import_shared.DeploymentTypeEnum.CLOUD;
7559
+ }
7560
+ }
7561
+ async function settleWithin(work, timeoutMs) {
7562
+ let timer;
7563
+ try {
7564
+ await Promise.race([
7565
+ work,
7566
+ new Promise((resolve) => {
7567
+ timer = setTimeout(resolve, timeoutMs);
7568
+ })
7569
+ ]);
7570
+ } finally {
7571
+ if (timer !== void 0) {
7572
+ clearTimeout(timer);
7573
+ }
7574
+ }
7575
+ }
7576
+ function startGatewayTelemetry(input) {
7577
+ const otlpUrl = telemetryBaseUrl(input.config.serverUrl);
7578
+ const telemetry = initNodeTelemetry({
7579
+ environment: environmentName(input.config),
7580
+ logger: stderrLogger,
7581
+ logsEnabled: false,
7582
+ // Counters in metrics.ts are created at import time, before this SDK
7583
+ // starts, so they stay no-ops. Do not turn metrics on until those
7584
+ // instruments are created after init.
7585
+ metricsEnabled: false,
7586
+ otlpHeaders: { Authorization: `Bearer ${input.apiKey}` },
7587
+ ...otlpUrl ? { otlpUrl } : {},
7588
+ serviceName: "gateway",
7589
+ serviceVersion: "0.0.1"
7590
+ }, getDefaultPolicy(deploymentTypeFor(input.config)));
7591
+ const mcpTelemetry = new McpClientTelemetry(telemetry.getTracer("gateway.mcp"));
7592
+ return {
7593
+ mcpTelemetry,
7594
+ shutdown: async () => {
7595
+ try {
7596
+ mcpTelemetry.endSession();
7597
+ } finally {
7598
+ await settleWithin(telemetry.shutdown(), TELEMETRY_SHUTDOWN_MS);
7599
+ }
7600
+ }
7601
+ };
7602
+ }
7603
+
7309
7604
  // ../../../gateway/dist/transports/mcp/mount.js
7310
7605
  init_cjs_shims();
7311
7606
  import { randomUUID as randomUUID4 } from "node:crypto";
@@ -7405,6 +7700,150 @@ function N3(Z, $, J, X, V) {
7405
7700
  return Z.registerResource($, J, { mimeType: p, ...X }, V);
7406
7701
  }
7407
7702
 
7703
+ // ../../../gateway/dist/capabilities/integration-metadata.js
7704
+ init_cjs_shims();
7705
+ var DEFAULT_LIMIT = 100;
7706
+ function labelPart(value) {
7707
+ return typeof value === "string" ? value.trim().replaceAll(/[.[\]]/g, "_") : "";
7708
+ }
7709
+ function arrayEntryLabel(value, index) {
7710
+ if (value && typeof value === "object") {
7711
+ const row = value;
7712
+ const name = labelPart(row.name);
7713
+ if (name) {
7714
+ const schema = labelPart(row.schema);
7715
+ return schema ? `${schema}.${name}` : name;
7716
+ }
7717
+ }
7718
+ return String(index);
7719
+ }
7720
+ function metadataEntries(value, path3 = "", entries = []) {
7721
+ if (value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
7722
+ entries.push({ path: path3, value });
7723
+ return entries;
7724
+ }
7725
+ if (Array.isArray(value)) {
7726
+ const seen = /* @__PURE__ */ new Set();
7727
+ value.forEach((entry, index) => {
7728
+ const label = arrayEntryLabel(entry, index);
7729
+ const unique = seen.has(label) ? `${label}#${index}` : label;
7730
+ seen.add(unique);
7731
+ metadataEntries(entry, `${path3}[${unique}]`, entries);
7732
+ });
7733
+ return entries;
7734
+ }
7735
+ if (value && typeof value === "object") {
7736
+ for (const [key2, entry] of Object.entries(value)) {
7737
+ metadataEntries(entry, path3 ? `${path3}.${key2}` : key2, entries);
7738
+ }
7739
+ }
7740
+ return entries;
7741
+ }
7742
+ async function getIntegrationMetadata(context2, input) {
7743
+ const principal = await ensurePrincipal(context2);
7744
+ if (principal.kind !== "ok") {
7745
+ return principal;
7746
+ }
7747
+ let applicationId;
7748
+ let label = sanitizeAgentFacingText(input.integrationId);
7749
+ try {
7750
+ const resolved = await resolveApplicationId(context2, principal.value, input.applicationId);
7751
+ applicationId = resolved.kind === "ok" ? resolved.value : void 0;
7752
+ const rows = await context2.server.getSupersetIntegrations({
7753
+ apiKey: principal.value.apiKey,
7754
+ ...applicationId && { applicationId },
7755
+ organizationId: principal.value.organizationId
7756
+ });
7757
+ const integration = rows.find((row) => row.id === input.integrationId);
7758
+ if (!integration) {
7759
+ return {
7760
+ ...applicationId && { applicationId },
7761
+ kind: "error",
7762
+ code: "integration_not_accessible",
7763
+ message: `Integration ${label} was not found or is not accessible.`
7764
+ };
7765
+ }
7766
+ const integrationName = sanitizeAgentFacingText(integration.name);
7767
+ const pluginId = sanitizeAgentFacingText(integration.pluginId);
7768
+ label = integrationName;
7769
+ if (!hasBuildPermission(integration)) {
7770
+ return {
7771
+ ...applicationId && { applicationId },
7772
+ kind: "error",
7773
+ code: "integration_not_permitted",
7774
+ message: `You do not have build permission on ${integrationName}.`
7775
+ };
7776
+ }
7777
+ if (!integrationIsToolSupported(integration.pluginId)) {
7778
+ return {
7779
+ ...applicationId && { applicationId },
7780
+ kind: "error",
7781
+ code: "integration_not_supported",
7782
+ message: `${integrationName} is a ${pluginId} integration, which this tool cannot inspect.`
7783
+ };
7784
+ }
7785
+ const profiles = await context2.server.getOrganizationProfiles({
7786
+ apiKey: principal.value.apiKey,
7787
+ organizationId: principal.value.organizationId
7788
+ });
7789
+ const profileKey = pickEditorProfileKey(context2.config.profileKey, profiles);
7790
+ const inventory = await context2.server.getAgentInventory({
7791
+ apiKey: principal.value.apiKey,
7792
+ organizationId: principal.value.organizationId
7793
+ });
7794
+ const orchestratorUrl = pickOrchestratorBaseUrl({
7795
+ agentType: inventory.agentType,
7796
+ agents: inventory.agents,
7797
+ profileKey
7798
+ });
7799
+ const scopedToken = await context2.server.issueScopedToken(applicationId ? {
7800
+ apiKey: principal.value.apiKey,
7801
+ applicationId,
7802
+ scope: "apps:update"
7803
+ } : {
7804
+ apiKey: principal.value.apiKey,
7805
+ integrationId: input.integrationId,
7806
+ scope: "integrations:build"
7807
+ });
7808
+ const metadata = await new HttpOrchestratorClient(orchestratorUrl).getMetadata({
7809
+ apiKey: principal.value.apiKey,
7810
+ integrationId: input.integrationId,
7811
+ profileKey,
7812
+ scopedToken
7813
+ });
7814
+ const sanitized = sanitizeAgentFacingValue(metadata);
7815
+ const search = input.search?.trim().toLowerCase();
7816
+ const matched = metadataEntries(sanitized).filter((entry) => !search || entry.path.toLowerCase().includes(search) || String(entry.value).toLowerCase().includes(search));
7817
+ const limit = input.limit ?? DEFAULT_LIMIT;
7818
+ const offset = input.offset ?? 0;
7819
+ const entries = matched.slice(offset, offset + limit);
7820
+ const nextOffset = offset + entries.length < matched.length ? offset + entries.length : null;
7821
+ return {
7822
+ kind: "ok",
7823
+ value: {
7824
+ ...applicationId && { applicationId },
7825
+ entries,
7826
+ hasMore: nextOffset !== null,
7827
+ integrationId: integration.id,
7828
+ integrationName,
7829
+ nextOffset,
7830
+ offset,
7831
+ pluginId,
7832
+ returnedCount: entries.length,
7833
+ totalCount: matched.length
7834
+ }
7835
+ };
7836
+ } catch (error) {
7837
+ const detail = sanitizeAgentFacingText(error instanceof Error ? error.message : "Unknown metadata error").replaceAll("\u2014", "-");
7838
+ return {
7839
+ ...applicationId && { applicationId },
7840
+ kind: "error",
7841
+ code: "integration_metadata_unavailable",
7842
+ message: `Could not load metadata for ${label}: ${detail}`
7843
+ };
7844
+ }
7845
+ }
7846
+
7408
7847
  // ../../../gateway/dist/capture/browser-instructions.js
7409
7848
  init_cjs_shims();
7410
7849
  var BROWSER_DRIVER_INSTRUCTIONS = `Browser capture (MUST):
@@ -8066,6 +8505,16 @@ function resolveToken(options, auth) {
8066
8505
  function superblocksProductCopy(text) {
8067
8506
  return text.replaceAll(/\bClark AI Apps\b/g, "Superblocks AI Apps").replaceAll(/\bClark\b/g, "Superblocks");
8068
8507
  }
8508
+ function completeToolAnnotations(annotations) {
8509
+ const readOnlyHint = annotations?.readOnlyHint ?? false;
8510
+ return {
8511
+ ...annotations,
8512
+ destructiveHint: annotations?.destructiveHint ?? (readOnlyHint ? false : true),
8513
+ idempotentHint: annotations?.idempotentHint ?? readOnlyHint,
8514
+ openWorldHint: annotations?.openWorldHint ?? true,
8515
+ readOnlyHint
8516
+ };
8517
+ }
8069
8518
  function registerAdminTools(server, options) {
8070
8519
  const registry = buildToolRegistry(toolDefinitions, "customer", {
8071
8520
  requireEntitledPlan: options.localAgentMode !== true
@@ -8076,7 +8525,7 @@ function registerAdminTools(server, options) {
8076
8525
  }
8077
8526
  const definition = toolDefinitions.find((d2) => d2.name === tool.name);
8078
8527
  server.registerTool(tool.name, {
8079
- annotations: tool.annotations,
8528
+ annotations: completeToolAnnotations(tool.annotations),
8080
8529
  description: superblocksProductCopy(tool.description ?? ""),
8081
8530
  inputSchema: gatewayAdminInputShape(tool.inputSchema),
8082
8531
  title: tool.title ?? definition?.title
@@ -8117,7 +8566,7 @@ function registerAdminTools(server, options) {
8117
8566
 
8118
8567
  // ../../../gateway/dist/transports/mcp/app-status-html.js
8119
8568
  init_cjs_shims();
8120
- var APP_STATUS_RESOURCE_URI = "ui://gateway/app-status-v6.html";
8569
+ var APP_STATUS_RESOURCE_URI = "ui://gateway/app-status-v8.html";
8121
8570
  var APP_STATUS_HTML = `<!DOCTYPE html>
8122
8571
  <html lang="en">
8123
8572
  <head>
@@ -8231,11 +8680,29 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8231
8680
  <script>
8232
8681
  (() => {
8233
8682
  const PROTOCOL_VERSION = "2026-01-26";
8683
+ // Statuses get_app reports when the app is still the empty starter
8684
+ // template. "building" is deliberately absent: the card only hears a
8685
+ // build finished if a new result arrives, so a stale badge would strand
8686
+ // the button.
8687
+ const UNBUILT_STATUSES = [
8688
+ "cancelled",
8689
+ "live_edit_terminated",
8690
+ "needs_decision",
8691
+ "no_changes",
8692
+ "timeout",
8693
+ ];
8694
+ const BLOCKED_ACTIONS = [
8695
+ "answer_question",
8696
+ "approve_plan",
8697
+ "retry_build",
8698
+ "retry_import",
8699
+ ];
8234
8700
  let nextId = 1;
8235
8701
  const pending = new Map();
8236
8702
  let applicationId = "";
8237
8703
  let appName = "";
8238
8704
  let commitId = "";
8705
+ let pendingAction = "";
8239
8706
  let editUrl = "";
8240
8707
  let previewUrl = "";
8241
8708
  let publishUrl = "";
@@ -8243,6 +8710,13 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8243
8710
  let canCallTools = false;
8244
8711
  let publishing = false;
8245
8712
  let lastHeight = 0;
8713
+ let refreshInFlight = false;
8714
+ let refreshTimer = 0;
8715
+ let refreshGeneration = 0;
8716
+ let refreshAttempts = 0;
8717
+ let pollAfterMs = 2000;
8718
+ const MIN_POLL_MS = 2000;
8719
+ const MAX_REFRESH_ATTEMPTS = 40;
8246
8720
 
8247
8721
  function post(message) {
8248
8722
  window.parent.postMessage(message, "*");
@@ -8332,6 +8806,31 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8332
8806
  }
8333
8807
  }
8334
8808
 
8809
+ /**
8810
+ * True when publishing would deploy the empty starter template.
8811
+ * pendingAction is the server's own "nothing to preview" signal;
8812
+ * wait_for_build is the building exception. Status is only a fallback
8813
+ * when the payload omitted pendingAction. loading/waiting with no
8814
+ * preview fail closed so Publish is not clickable before get_app
8815
+ * returns.
8816
+ */
8817
+ function nothingToPublish() {
8818
+ if (previewUrl || publishUrl) {
8819
+ return false;
8820
+ }
8821
+ if (pendingAction === "wait_for_build") {
8822
+ return false;
8823
+ }
8824
+ if (BLOCKED_ACTIONS.indexOf(pendingAction) !== -1) {
8825
+ return true;
8826
+ }
8827
+ const badge = element("status").textContent;
8828
+ if (!badge || badge === "loading" || badge === "waiting") {
8829
+ return true;
8830
+ }
8831
+ return UNBUILT_STATUSES.indexOf(badge) !== -1;
8832
+ }
8833
+
8335
8834
  /**
8336
8835
  * Keep URLs in memory for openLink \u2014 never print them (preview JWTs are
8337
8836
  * huge and ugly in the card).
@@ -8346,7 +8845,10 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8346
8845
  : "Publish app";
8347
8846
  element("publishApp").disabled = publishUrl
8348
8847
  ? !canOpenLinks
8349
- : !applicationId || !canCallTools || publishing;
8848
+ : !applicationId ||
8849
+ !canCallTools ||
8850
+ publishing ||
8851
+ nothingToPublish();
8350
8852
  // Only warn about what is actually broken. Hosts that do open links
8351
8853
  // handle local http fine; if one refuses, refused() says so then.
8352
8854
  if (!canOpenLinks && (editUrl || previewUrl) && !publishUrl) {
@@ -8418,6 +8920,11 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8418
8920
  if (typeof value.commitId === "string") {
8419
8921
  commitId = value.commitId;
8420
8922
  }
8923
+ if (typeof value.pendingAction === "string") {
8924
+ pendingAction = value.pendingAction;
8925
+ } else if (typeof value.status === "string") {
8926
+ pendingAction = "";
8927
+ }
8421
8928
  if (typeof value.screenshotBase64 === "string") {
8422
8929
  showScreenshot(value.screenshotBase64, "image/jpeg");
8423
8930
  }
@@ -8430,6 +8937,9 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8430
8937
  if (typeof value.publishUrl === "string") {
8431
8938
  publishUrl = webUrl(value.publishUrl);
8432
8939
  }
8940
+ if (typeof value.nextPollAfterMs === "number") {
8941
+ pollAfterMs = value.nextPollAfterMs;
8942
+ }
8433
8943
  // Hosts that deliver URLs without a status left the badge on the HTML
8434
8944
  // default ("loading") even after the app was built.
8435
8945
  const badge = element("status").textContent;
@@ -8444,29 +8954,91 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8444
8954
  }
8445
8955
 
8446
8956
  /**
8447
- * When the host opened the card with tool input (applicationId) but never
8448
- * pushed a tool result, refresh ourselves so the badge is not stuck on
8449
- * "loading" after the build finished.
8957
+ * Re-ask get_app when the host gave us no result, or while status is
8958
+ * still building. wait:false and ensurePreview:false so polls only
8959
+ * ask for status. Honor nextPollAfterMs; 0 means stop.
8450
8960
  */
8961
+ function clearRefreshTimer() {
8962
+ if (refreshTimer) {
8963
+ clearTimeout(refreshTimer);
8964
+ refreshTimer = 0;
8965
+ }
8966
+ }
8967
+
8968
+ function retryDelay() {
8969
+ return Math.max(MIN_POLL_MS, pollAfterMs || MIN_POLL_MS);
8970
+ }
8971
+
8972
+ function scheduleRefresh(delayMs) {
8973
+ clearRefreshTimer();
8974
+ if (refreshAttempts >= MAX_REFRESH_ATTEMPTS) {
8975
+ note("Stopped checking whether the app is still building.");
8976
+ return;
8977
+ }
8978
+ refreshTimer = setTimeout(() => {
8979
+ refreshTimer = 0;
8980
+ refreshFromServer();
8981
+ }, delayMs);
8982
+ }
8983
+
8451
8984
  function refreshFromServer() {
8452
- if (!canCallTools || !applicationId || editUrl) {
8985
+ clearRefreshTimer();
8986
+ if (!canCallTools || !applicationId || refreshInFlight) {
8987
+ return;
8988
+ }
8989
+ if (typeof document.hidden === "boolean" && document.hidden) {
8990
+ scheduleRefresh(retryDelay());
8991
+ return;
8992
+ }
8993
+ const badge = element("status").textContent;
8994
+ if (editUrl && badge !== "building") {
8995
+ return;
8996
+ }
8997
+ if (refreshAttempts >= MAX_REFRESH_ATTEMPTS) {
8998
+ note("Stopped checking whether the app is still building.");
8453
8999
  return;
8454
9000
  }
9001
+ refreshAttempts += 1;
9002
+ const generation = refreshGeneration;
9003
+ refreshInFlight = true;
8455
9004
  request("tools/call", {
8456
9005
  name: "get_app",
8457
- arguments: { applicationId },
9006
+ arguments: {
9007
+ applicationId,
9008
+ ensurePreview: false,
9009
+ wait: false,
9010
+ },
8458
9011
  })
8459
9012
  .then((result) => {
9013
+ refreshInFlight = false;
9014
+ if (generation !== refreshGeneration) {
9015
+ if (element("status").textContent === "building") {
9016
+ scheduleRefresh(retryDelay());
9017
+ }
9018
+ return;
9019
+ }
8460
9020
  if (!result || result.isError) {
9021
+ scheduleRefresh(retryDelay());
8461
9022
  return;
8462
9023
  }
8463
9024
  applyPayload(result);
8464
9025
  if (result.structuredContent) {
8465
9026
  applyPayload(result.structuredContent);
8466
9027
  }
9028
+ if (element("status").textContent !== "building") {
9029
+ return;
9030
+ }
9031
+ if (pollAfterMs === 0) {
9032
+ return;
9033
+ }
9034
+ scheduleRefresh(retryDelay());
8467
9035
  })
8468
9036
  .catch(() => {
8469
- // Host declined; stay on whatever we have.
9037
+ refreshInFlight = false;
9038
+ if (generation !== refreshGeneration) {
9039
+ return;
9040
+ }
9041
+ scheduleRefresh(retryDelay());
8470
9042
  });
8471
9043
  }
8472
9044
 
@@ -8519,6 +9091,10 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8519
9091
  if (!applicationId || !canCallTools || publishing) {
8520
9092
  return;
8521
9093
  }
9094
+ if (nothingToPublish()) {
9095
+ note("Nothing to publish yet: this turn did not build the app.");
9096
+ return;
9097
+ }
8522
9098
  publishing = true;
8523
9099
  renderActions();
8524
9100
  note("Publishing\u2026");
@@ -8602,6 +9178,10 @@ var APP_STATUS_HTML = `<!DOCTYPE html>
8602
9178
  if (params.structuredContent) {
8603
9179
  applyPayload(params.structuredContent);
8604
9180
  }
9181
+ refreshGeneration += 1;
9182
+ if (element("status").textContent === "building") {
9183
+ refreshFromServer();
9184
+ }
8605
9185
  }
8606
9186
  if (method === "ui/notifications/tool-input" && params.arguments) {
8607
9187
  applyPayload(params.arguments);
@@ -8931,6 +9511,24 @@ function createProgressNotifier(extra) {
8931
9511
  }
8932
9512
 
8933
9513
  // ../../../gateway/dist/transports/mcp/mount.js
9514
+ var DESTRUCTIVE_TOOL_ANNOTATIONS = {
9515
+ destructiveHint: true,
9516
+ idempotentHint: false,
9517
+ openWorldHint: true,
9518
+ readOnlyHint: false
9519
+ };
9520
+ var NON_DESTRUCTIVE_WRITE_TOOL_ANNOTATIONS = {
9521
+ destructiveHint: false,
9522
+ idempotentHint: false,
9523
+ openWorldHint: true,
9524
+ readOnlyHint: false
9525
+ };
9526
+ var READ_ONLY_TOOL_ANNOTATIONS = {
9527
+ destructiveHint: false,
9528
+ idempotentHint: true,
9529
+ openWorldHint: true,
9530
+ readOnlyHint: true
9531
+ };
8934
9532
  var eventCursorInputSchema = external_exports.object({
8935
9533
  streams: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
8936
9534
  version: external_exports.unknown().optional()
@@ -8951,10 +9549,11 @@ Name the builder "Superblocks" in every word you write. Users sometimes call it
8951
9549
  Use these tools whenever the user asks to build, change, import, or ship an app, whichever of those names they reach for.
8952
9550
 
8953
9551
  - start_app: create a new application and hand a prompt to Superblocks. Returns as soon as Superblocks accepts, with status "building". Superblocks names it unless a name is given.
8954
- - import_app: import an existing app from a ZIP (or .tgz/.gz) into Superblocks and start a Superblocks migration. Pass the archive's file name as zipPath \u2014 the gateway opens the file on this machine itself. Archives larger than 1 MB are rejected \u2014 they almost certainly include node_modules; re-export without install artifacts. Optional prompt carries extra intent (e.g. "make it more secure"). Returns like start_app with status "building".
9552
+ - import_app: import an existing app from a ZIP (or .tgz/.gz) into Superblocks and start a Superblocks migration. Pass the archive's file name as zipPath \u2014 the gateway opens the file on this machine itself. Archives larger than 1 MB are rejected \u2014 they almost certainly include node_modules; re-export without install artifacts. Optional prompt carries extra intent (e.g. "make it more secure"). Returns like start_app with status "building". Pass applicationId only when retrying a failed import into the application that call already created.
8955
9553
  - edit_app: send a follow-up prompt (including the answer when Superblocks asked a question) for an existing application. Also returns at status "building". Defaults to the most recent app, so an applicationId is only needed to target a different app.
8956
9554
  - check_app_progress: wait for the next thing Superblocks does and return it. It returns the moment Superblocks says anything, and after ~10 seconds of silence at the latest. "activity" holds Superblocks' own words since the previous call, in order; a quiet poll still returns a short heartbeat with elapsedSeconds.
8957
- - get_app: return editor and preview URLs for the recent or specified app (builds a private preview when needed). Prefer this after status "ready" so the user can open the live app. Hosts that support MCP Apps show the status card (Open editor / Open preview) on this call \u2014 not on check_app_progress or preview_app \u2014 so only one card opens. When Superblocks has written code the tool includes a screenshot: the live Vite canvas (library peer) if a held session exists, otherwise the signed-in preview. Never open canvas.doNotOpen (the edit URL) to take that screenshot. It refuses to build a preview of an app Superblocks has not written yet: while a plan or question is outstanding it returns status "needs_decision" with "pendingAction", while a turn is running it returns status "building", and when the last turn ended without writing anything it returns that turn's status ("timeout", "live_edit_terminated", "no_changes" or "cancelled") with pendingAction "retry_build". In each case there are no preview URLs and no screenshot \u2014 do the pendingAction first rather than calling get_app again.
9555
+ - get_app: return editor and preview URLs for the recent or specified app (builds a private preview when needed). Prefer this after status "ready" so the user can open the live app. Hosts that support MCP Apps show the status card (Open editor / Open preview) on this call \u2014 not on check_app_progress or preview_app \u2014 so only one card opens. When Superblocks has written code the tool includes a screenshot: the live Vite canvas (library peer) if a held session exists, otherwise the signed-in preview. Never open canvas.doNotOpen (the edit URL) to take that screenshot. It refuses to build a preview of an app Superblocks has not written yet: while a plan or question is outstanding it returns status "needs_decision" with "pendingAction", while a turn is running it returns status "building", and when the last turn ended without writing anything it returns that turn's status ("timeout", "live_edit_terminated", "no_changes" or "cancelled") with pendingAction "retry_build" for ordinary prompts or pendingAction "retry_import" for imports. In each case there are no preview URLs and no screenshot \u2014 do the pendingAction first rather than calling get_app again.
9556
+ - get_integration_metadata: inspect the tables, columns, and types in a connected integration. It needs no application and never executes an integration action, so do not call start_app or hunt through list_applications to satisfy it. Pass applicationId only for an integration that belongs to one application, such as a Native DB. Use search, limit, and offset to page large results. get_integration_config_schema is the JSON form for create_integration; it does not inspect connected data.
8958
9557
  - preview_app: build the application's current work and return a URL that runs it, without deploying it \u2014 the editor's Preview button. Nobody else can reach a preview. Text/markdown only (no MCP Apps widget); use get_app instead when you want the status card.
8959
9558
  - publish_app: deploy an application and wait until it is live. It commits the current work first, so a commitId is only needed to publish an earlier commit.
8960
9559
 
@@ -8962,21 +9561,25 @@ A build takes two to four minutes, and start_app/edit_app/import_app return with
8962
9561
 
8963
9562
  The user sees nothing at all while a tool call is outstanding, so between two calls always write out the new "activity" lines as a short message in your own reply \u2014 quote or paraphrase them, oldest first, before calling check_app_progress again. Do not batch them up for a summary at the end, and do not go two calls in a row without writing something: the point of the loop is that the user watches the build happen. When a call comes back with only a heartbeat (no new Superblocks words), say Superblocks is still working and how long it has been going, then poll again.
8964
9563
 
8965
- status "ready" means the turn finished: report the "reply" field, then call get_app (not preview_app as well \u2014 calling both used to open two widgets) so the user gets Open preview / an https link or a screenshot. status "needs_decision" means Superblocks is waiting \u2014 often with a plan \u2014 so stop polling and put the decision to the user. When "decision.kind" is "plan", show the plan markdown, then invite them to build it as written or say what to change \u2014 the same fork the editor's Build-it button offers. Ask that as an ordinary closing question in your own words; do not turn it into a numbered or bulleted menu, and do not wrap the choices in quotation marks. When they say "Build it", "approve", "looks good", or "go ahead", you MUST call edit_app with planAction "approve" and omit prompt (do not re-send the plan, and do not put "approve" or "Build it" in the prompt field \u2014 that is refine feedback to Superblocks, not the editor Build-it path). When they want changes, call edit_app with planAction "refine" and their feedback as prompt. When "decision.kind" is "multi_choice", relay the question and options and send their answer with edit_app. Do not claim the app is built while status is "needs_decision". status "no_changes" means the Superblocks job ended without building anything: relay reply, say no app was built, and do not present the edit URL as a finished app. status "live_edit_terminated" means the live-edit session that was to run the turn died before it built anything, or never opened at all \u2014 the prompt was fine and nothing timed out, so relay reply, tell the user the session did not survive, and offer to send the same instruction again with edit_app. status "detached" means Superblocks is still working but the gateway can no longer see it \u2014 usually because the app is open in a browser editor, which takes over Superblocks updates. Stop polling, say so, and point the user at the edit URL. status "unknown" means nothing is in flight for that app. A checkpointCommitId means Superblocks work is saved and the edit URL opens the finished app; when viewStatus is unknown, say the app may still be finishing in the editor.
9564
+ status "ready" means the turn finished: report the "reply" field, then call get_app (not preview_app as well \u2014 calling both used to open two widgets) so the user gets Open preview / an https link or a screenshot. status "needs_decision" means Superblocks is waiting \u2014 often with a plan \u2014 so stop polling and put the decision to the user. When "decision.kind" is "plan", show the plan markdown, then invite them to build it as written or say what to change \u2014 the same fork the editor's Build-it button offers. Ask that as an ordinary closing question in your own words; do not turn it into a numbered or bulleted menu, and do not wrap the choices in quotation marks. When they say "Build it", "approve", "looks good", or "go ahead", you MUST call edit_app with planAction "approve" and omit prompt (do not re-send the plan, and do not put "approve" or "Build it" in the prompt field \u2014 that is refine feedback to Superblocks, not the editor Build-it path). When they want changes, call edit_app with planAction "refine" and their feedback as prompt. When "decision.kind" is "multi_choice", relay the question and options and send their answer with edit_app. Do not claim the app is built while status is "needs_decision". status "no_changes" means the Superblocks job ended without building anything: relay reply, say no app was built, and do not present the edit URL as a finished app. status "live_edit_terminated" means the live-edit session that was to run the turn died before it built anything, or never opened at all \u2014 relay reply, tell the user the session did not survive, and follow its pendingAction to retry with edit_app or import_app. status "detached" means Superblocks is still working but the gateway can no longer see it \u2014 usually because the app is open in a browser editor, which takes over Superblocks updates. Stop polling, say so, and point the user at the edit URL. status "unknown" means nothing is in flight for that app. A checkpointCommitId means Superblocks work is saved and the edit URL opens the finished app; when viewStatus is unknown, say the app may still be finishing in the editor.
9565
+
9566
+ When get_app returns a screenshot, inspect it yourself before reporting that the app looks correct. If it shows skeletons, spinners, empty tables or charts, or "Loading...", call get_app again a few seconds later instead of treating that as a defect. If it shows a problem the user would plainly recognize as wrong, call edit_app once with a concrete correction, follow that turn to completion, and inspect the next get_app screenshot. Otherwise describe what you see and ask the user whether to fix it.
8966
9567
 
8967
9568
  start_app, edit_app, and import_app default to Plan mode (Superblocks proposes a plan before writing). Pass mode "BUILD" only when the user asks to skip planning and build immediately. Approving a plan after start_app or import_app is always a follow-up edit_app with planAction "approve" \u2014 never a second start_app/import_app with prompt "approve". Once the app has run in Build mode, later edit_app calls stay in Build mode on their own: you do not need to re-send mode "BUILD", and a new instruction is not a fresh planning round. Send mode "PLAN" only when the user explicitly asks to plan again before building. Every start_app / edit_app / import_app result reports the "mode" the turn ran in, so you can tell the user whether Superblocks is planning or building rather than guessing \u2014 and if a result comes back "PLAN" after a long gap, the build session was recycled rather than the user asking to plan, so pass mode "BUILD" again to carry on building. editUrl / previewUrl / publishUrl may appear in structured JSON for openLink buttons \u2014 do not dump raw URLs (especially preview JWTs) into the chat. Prefer the MCP Apps Open editor / Open preview buttons from get_app. Claude Desktop can only openLink https URLs; when previewUrl is http, say so briefly and rely on any screenshot image the tool returned rather than pasting the URL.
8968
9569
 
8969
9570
  Once a build reaches "ready", call get_app so the user can open the app, then offer publish_app to deploy for their organization when they ask. Prefer get_app over preview_app after a build \u2014 get_app already ensures a private preview and is the only tool that opens the MCP Apps status card. Only publish when the user asks. If preview_app or get_app comes back with status "building", the URL is already correct; tell the user it is still building and call again to check.
8970
9571
 
8971
- There is nothing to preview until Superblocks has written code, so get_app is not the way out of a plan, a question, or a turn that failed. When it answers status "needs_decision" (pendingAction "approve_plan" or "answer_question"), the app is still the empty starter template: put the decision to the user, send their answer with edit_app, and only call get_app once a turn has finished. When it answers "timeout", "live_edit_terminated", "no_changes" or "cancelled" with pendingAction "retry_build", that turn built nothing: tell the user so plainly, and send the instruction again with edit_app if they want to retry. Repeating get_app instead opens another status card and tells the user nothing new.
9572
+ There is nothing to preview until Superblocks has written code, so get_app is not the way out of a plan, a question, or a turn that failed. When it answers status "needs_decision" (pendingAction "approve_plan" or "answer_question"), the app is still the empty starter template: put the decision to the user, send their answer with edit_app, and only call get_app once a turn has finished. When it answers "timeout", "live_edit_terminated", "no_changes" or "cancelled" with pendingAction "retry_build", that turn built nothing: tell the user so plainly, and send the instruction again with edit_app if they want to retry. For pendingAction "retry_import", call import_app again with the same archive and applicationId. One of those statuses can arrive with no pendingAction at all, which means the gateway knows the turn wrote nothing but not how it was started: say so, and pick the retry from what this conversation already knows \u2014 import_app with the archive and applicationId for an app you imported, edit_app with the same prompt otherwise. Repeating get_app instead opens another status card and tells the user nothing new.
8972
9573
 
8973
9574
  Superblocks tests what it builds: it opens the app in a browser and runs its APIs, and the test run arrives as ordinary "activity" lines ("Testing the orders page", "Test passed: \u2026", "Tests failed: \u2026"). Relay those lines like any other activity, and say which cases passed and which failed \u2014 a test run is the only evidence the user has that the app actually works. A failing test is a build signal, not an auth problem: it means the app has a bug Superblocks is about to work on, so keep polling and never tell the user to sign in again or re-enter credentials over one.
8974
9575
 
8975
- A failed call still names the application it was working on. start_app and import_app create the application before the build can start, so an error from either one leaves an application that exists and belongs to this conversation, and the error says which: read the "applicationId" field, never a UUID out of the message text. Never take an error to mean nothing happened. Do not answer a failed start_app with a second start_app \u2014 that abandons the app you already have and creates a duplicate. When the error carries pendingAction "retry_build" \u2014 a "live_edit_unavailable" session that would not open, or a turn that ran out of budget \u2014 send the same prompt again with edit_app and that applicationId. A failed import_app carries no such recovery, because edit_app cannot resupply the archive the migration prompt reads: that application is empty and nothing can continue it in place, so name it to the user and let them decide whether to import again. Every edit_app error names its applicationId too, which is the one place to see which app a call that omitted the id actually ran on.
9576
+ A failed call still names the application it was working on. start_app and import_app create the application before the build can start, so an error from either one leaves an application that exists and belongs to this conversation, and the error says which: read the "applicationId" field, never a UUID out of the message text. Never take an error to mean nothing happened. Do not answer a failed start_app with a second start_app \u2014 that abandons the app you already have and creates a duplicate. When the error carries pendingAction "retry_build" \u2014 a "live_edit_unavailable" session that would not open, or a turn that ran out of budget \u2014 send the same prompt again with edit_app and that applicationId. When import_app returns pendingAction "retry_import", call import_app again with the same archive and applicationId so it resumes the existing app instead of creating another one. Every edit_app error names its applicationId too, which is the one place to see which app a call that omitted the id actually ran on.
9577
+
9578
+ A cancelled call does not stop the build, and it is not permission to start over. Cancelling only ends the waiting \u2014 Superblocks carries on, and the "cancelled" error names the application it was driving in "applicationId". Read that id, call check_app_progress or get_app on it, and act on what comes back. When the user then asks to redo, retry, or resume an import, that is a request to finish the application you already have: never answer it with an import_app that omits applicationId, which builds a second app and strands the first. The same holds when no pendingAction is in front of you \u2014 after a cancel, or in a later session. If the app came from an import, the way back in is import_app with the same archive and that applicationId; if you cannot tell which application the user means, ask rather than create one.
8976
9579
 
8977
9580
  Prompts are forwarded to Superblocks verbatim \u2014 pass the user's wording rather than a summary.
8978
9581
 
8979
- This connector is the single Superblocks MCP: Builder tools (start_app, import_app, edit_app, check_app_progress, get_app, preview_app, publish_app) and Admin tools (integrations, apps, users, folders, deploy_application, and the rest of the customer Admin surface) share this endpoint. Prefer create_integration / update_integration / list_integrations here when Superblocks needs a missing Postgres, REST, or other datasource \u2014 do not send the user to a second MCP. create_integration is Admin CRUD for org datasources; start_app creates a new application and hands a prompt to Superblocks. deploy_application is Admin deploy of an existing commit; publish_app is the Builder path that commits current work and waits until the app is live. Omit base_url on Admin tools unless targeting a different control plane \u2014 the gateway injects its configured Server URL. checkout_application is not exposed on this network surface (host filesystem writes); use the CLI/workspace checkout path instead.
9582
+ This connector is the single Superblocks MCP: Builder tools (start_app, import_app, edit_app, check_app_progress, get_app, get_integration_metadata, preview_app, publish_app) and Admin tools (integrations, apps, users, folders, deploy_application, and the rest of the customer Admin surface) share this endpoint. Prefer create_integration / update_integration / list_integrations here when Superblocks needs a missing Postgres, REST, or other datasource \u2014 do not send the user to a second MCP. Call get_integration_config_schema with the plugin_id before create_integration, then pass name, plugin_id, and configuration \u2014 never the raw integrations API envelope. create_integration is Admin CRUD for org datasources; start_app creates a new application and hands a prompt to Superblocks. deploy_application is Admin deploy of an existing commit; publish_app is the Builder path that commits current work and waits until the app is live. Omit base_url on Admin tools unless targeting a different control plane \u2014 the gateway injects its configured Server URL. checkout_application is not exposed on this network surface (host filesystem writes); use the CLI/workspace checkout path instead.
8980
9583
 
8981
9584
  This connection is already authenticated and already pointed at one Superblocks Server, so there is no setup, login, or auth-status call to make first. Call the tool that does the job \u2014 list_integrations to see the org's datasources, start_app to create an application \u2014 and read its error if something is genuinely wrong. Do not look for a tool that reports credentials or environments; there is none, and asking for one costs the user a turn.
8982
9585
 
@@ -8986,7 +9589,7 @@ For import_app, the archive never travels through you. A file the user attached
8986
9589
 
8987
9590
  ${BROWSER_DRIVER_INSTRUCTIONS}`;
8988
9591
  function createMcpServer(deps) {
8989
- const context = async (progress, notify, signal) => ({
9592
+ const context2 = async (progress, notify, signal) => ({
8990
9593
  caller: callerFrom(),
8991
9594
  captureLibraryScreenshot: captureLibraryScreenshotWithPlaywright,
8992
9595
  capturePreviewScreenshot: capturePreviewScreenshotWithPlaywright,
@@ -8996,6 +9599,9 @@ function createMcpServer(deps) {
8996
9599
  progress.push(event);
8997
9600
  notify?.(event.message);
8998
9601
  },
9602
+ onPrincipalResolved: (principal) => {
9603
+ deps.mcpTelemetry?.setOrganizationId(principal.organizationId);
9604
+ },
8999
9605
  principal: principalFrom(deps),
9000
9606
  progressCursors: deps.progressCursors,
9001
9607
  recentApps: deps.recentApps,
@@ -9008,22 +9614,22 @@ function createMcpServer(deps) {
9008
9614
  gatewayDebugStack("tool started", { "tool.name": toolName });
9009
9615
  const progress = [];
9010
9616
  const notify = createProgressNotifier(extra);
9011
- let result;
9012
- if (!deps.cliApiKey) {
9013
- gatewayDebug("tool short-circuited", {
9014
- "tool.name": toolName,
9015
- "tool.reason": "missing_cli_session"
9016
- });
9017
- result = {
9018
- kind: "error",
9019
- code: "unauthenticated",
9020
- message: "This Gateway has no CLI session. Run: superblocks login"
9021
- };
9022
- } else {
9617
+ const execute = async () => {
9618
+ if (!deps.cliApiKey) {
9619
+ gatewayDebug("tool short-circuited", {
9620
+ "tool.name": toolName,
9621
+ "tool.reason": "missing_cli_session"
9622
+ });
9623
+ return {
9624
+ kind: "error",
9625
+ code: "unauthenticated",
9626
+ message: "This Gateway has no CLI session. Run: superblocks login"
9627
+ };
9628
+ }
9023
9629
  try {
9024
9630
  const signal = extra?.signal;
9025
- const capabilityContext = await context(progress, notify, signal);
9026
- result = await capability(capabilityContext, () => {
9631
+ const capabilityContext = await context2(progress, notify, signal);
9632
+ return await capability(capabilityContext, () => {
9027
9633
  for (let index = progress.length - 1; index >= 0; index -= 1) {
9028
9634
  if (progress[index]?.type === "completed") {
9029
9635
  progress.splice(index, 1);
@@ -9032,13 +9638,23 @@ function createMcpServer(deps) {
9032
9638
  });
9033
9639
  } catch (error) {
9034
9640
  console.error("gateway capability failed", error);
9035
- result = {
9641
+ return {
9036
9642
  kind: "error",
9037
9643
  code: "capability_failed",
9038
9644
  message: error instanceof Error ? error.message : "The gateway failed for an unknown reason."
9039
9645
  };
9040
9646
  }
9041
- }
9647
+ };
9648
+ const client = server.server.getClientVersion();
9649
+ const result = deps.mcpTelemetry ? await deps.mcpTelemetry.runTool({
9650
+ ...client ? {
9651
+ client: {
9652
+ name: client.name,
9653
+ version: client.version
9654
+ }
9655
+ } : {},
9656
+ toolName
9657
+ }, execute) : await execute();
9042
9658
  const resultStatus = result.kind === "ok" && result.value && typeof result.value === "object" && "status" in result.value && typeof result.value.status === "string" ? result.value.status : void 0;
9043
9659
  gatewayDebug("tool finished", {
9044
9660
  "progress.event_count": progress.length,
@@ -9064,12 +9680,12 @@ function createMcpServer(deps) {
9064
9680
  title: "Superblocks",
9065
9681
  version: "0.0.1"
9066
9682
  }, { instructions: SERVER_INSTRUCTIONS });
9067
- const progressWithDecisionForm = async (context2, input, extra, forgetFinishedTurn) => {
9683
+ const progressWithDecisionForm = async (context3, input, extra, forgetFinishedTurn) => {
9068
9684
  gatewayDebug("progress decision flow started", {
9069
9685
  "application.id": input.applicationId,
9070
9686
  "progress.cursor_provided": Boolean(input.cursor)
9071
9687
  });
9072
- const result = await checkAppProgress(context2, input);
9688
+ const result = await checkAppProgress(context3, input);
9073
9689
  const decision = pendingDecision(result);
9074
9690
  if (!decision) {
9075
9691
  gatewayDebug("progress decision flow finished", {
@@ -9089,7 +9705,7 @@ function createMcpServer(deps) {
9089
9705
  const resolved = await resolveDecisionByElicitation({
9090
9706
  apply: (answer) => {
9091
9707
  forgetFinishedTurn();
9092
- return editApp(context2, {
9708
+ return editApp(context3, {
9093
9709
  applicationId: input.applicationId,
9094
9710
  idempotencyKey: `mcp-decision:${randomUUID4()}`,
9095
9711
  wait: "ack",
@@ -9121,7 +9737,20 @@ function createMcpServer(deps) {
9121
9737
  });
9122
9738
  }
9123
9739
  function registerBuilderTools() {
9740
+ server.registerTool("get_integration_metadata", {
9741
+ annotations: READ_ONLY_TOOL_ANNOTATIONS,
9742
+ description: "Inspect the tables, columns, and types in a connected Superblocks integration. Needs no application and never executes an integration action. Pass integrationId, which list_integrations returns. A large result comes back paged: narrow it with search, take more or fewer entries with limit, and continue from nextOffset with offset. Requires build permission on the integration. Do not use this to learn how to create an integration; that is get_integration_config_schema.",
9743
+ inputSchema: {
9744
+ applicationId: external_exports.string().uuid().optional().describe("Only for an integration owned by a single application, such as a Native DB. Leave unset otherwise; do not go looking for an application to supply."),
9745
+ integrationId: external_exports.string().uuid(),
9746
+ limit: external_exports.number().int().min(1).max(200).optional(),
9747
+ offset: external_exports.number().int().min(0).optional(),
9748
+ search: external_exports.string().min(1).optional()
9749
+ },
9750
+ title: "Get Integration Metadata"
9751
+ }, async (input, extra) => run("get_integration_metadata", (context3) => getIntegrationMetadata(context3, input), extra));
9124
9752
  server.registerTool("start_app", {
9753
+ annotations: NON_DESTRUCTIVE_WRITE_TOOL_ANNOTATIONS,
9125
9754
  description: 'Create a Superblocks application and hand a prompt to Superblocks in Plan mode by default. Returns as soon as Superblocks accepts, with status "building" and an edit URL; follow with check_app_progress until status is no longer "building". When Superblocks returns needs_decision with a plan and the user says "Build it", call edit_app with planAction "approve" (omit prompt) \u2014 do not call start_app again with prompt "approve". Pass mode "BUILD" to skip planning. Superblocks names the application unless name is given. An error from this tool does not mean nothing happened: the application is created before the build starts, so the error names it in "applicationId". Retry that app with edit_app rather than calling start_app another time, which would leave the first one abandoned.',
9126
9755
  inputSchema: {
9127
9756
  branch: external_exports.string().optional(),
@@ -9134,7 +9763,7 @@ function createMcpServer(deps) {
9134
9763
  // the tool name: a host that ranks tools by title has to be able to find
9135
9764
  // this one from the request.
9136
9765
  title: "Create Superblocks App"
9137
- }, async ({ branch, idempotencyKey, mode, name, prompt }, extra) => run("start_app", (context2) => startApp(context2, {
9766
+ }, async ({ branch, idempotencyKey, mode, name, prompt }, extra) => run("start_app", (context3) => startApp(context3, {
9138
9767
  branch,
9139
9768
  idempotencyKey: idempotencyKey ?? `mcp-start:${randomUUID4()}`,
9140
9769
  mode,
@@ -9146,8 +9775,10 @@ function createMcpServer(deps) {
9146
9775
  wait: "ack"
9147
9776
  }), extra));
9148
9777
  server.registerTool("import_app", {
9149
- description: `Import an existing app from a ZIP/.tgz/.gz archive into Superblocks and start a Superblocks migration. Pass the archive's file name (or its full path on this machine) as zipPath: the gateway reads the file itself, so a path from your own sandbox is fine as long as the name matches the file the user has. Never encode the archive as base64 \u2014 zipBase64 only carries test fixtures. Archives larger than 1 MB are rejected \u2014 exclude node_modules. Optional prompt adds intent such as hardening security. Returns status "building"; follow with check_app_progress. Defaults to Plan mode \u2014 when Superblocks returns a plan and the user says "Build it", call edit_app with planAction "approve" (omit prompt); do not call import_app again with prompt "approve". An error from this tool does not mean nothing happened: the application is created before the migration starts, so the error names it in "applicationId". That application is empty \u2014 the migration never ran \u2014 and nothing can continue it in place, so say it exists and let the user decide whether to import again rather than silently retrying.`,
9778
+ annotations: DESTRUCTIVE_TOOL_ANNOTATIONS,
9779
+ description: `Import an existing app from a ZIP/.tgz/.gz archive into Superblocks and start a Superblocks migration. Pass the archive's file name (or its full path on this machine) as zipPath: the gateway reads the file itself, so a path from your own sandbox is fine as long as the name matches the file the user has. Never encode the archive as base64 \u2014 zipBase64 only carries test fixtures. Archives larger than 1 MB are rejected \u2014 exclude node_modules. Optional prompt adds intent such as hardening security. Returns status "building"; follow with check_app_progress. Defaults to Plan mode \u2014 when Superblocks returns a plan and the user says "Build it", call edit_app with planAction "approve" (omit prompt); do not call import_app again with prompt "approve". An error from this tool does not mean nothing happened: the application is created before the migration starts, so the error names it in "applicationId". When it returns pendingAction "retry_import", call import_app again with the same archive and applicationId to resume that application instead of creating another one.`,
9150
9780
  inputSchema: {
9781
+ applicationId: external_exports.string().uuid().optional(),
9151
9782
  branch: external_exports.string().optional(),
9152
9783
  idempotencyKey: external_exports.string().optional(),
9153
9784
  mode: external_exports.enum(["BUILD", "PLAN"]).optional(),
@@ -9167,7 +9798,8 @@ function createMcpServer(deps) {
9167
9798
  zipPath: external_exports.string().min(1).optional()
9168
9799
  },
9169
9800
  title: "Import App"
9170
- }, async ({ branch, idempotencyKey, mode, name, prompt, source, zipBase64, zipPath }, extra) => run("import_app", (context2) => importApp(context2, {
9801
+ }, async ({ applicationId, branch, idempotencyKey, mode, name, prompt, source, zipBase64, zipPath }, extra) => run("import_app", (context3) => importApp(context3, {
9802
+ applicationId,
9171
9803
  branch,
9172
9804
  idempotencyKey: idempotencyKey ?? `mcp-import:${randomUUID4()}`,
9173
9805
  mode,
@@ -9179,6 +9811,7 @@ function createMcpServer(deps) {
9179
9811
  zipPath
9180
9812
  }), extra));
9181
9813
  server.registerTool("edit_app", {
9814
+ annotations: DESTRUCTIVE_TOOL_ANNOTATIONS,
9182
9815
  description: 'Forward a prompt to Superblocks for the recent or specified application. Defaults to Plan mode until the app has run in Build mode; after that later edits keep building directly \u2014 you do not need to pass mode again. Pass mode "PLAN" only when the user explicitly asks to plan before building. The result reports the "mode" the turn ran in; a "PLAN" result after a long gap means the build session was recycled, so pass mode "BUILD" again rather than treating it as a new planning round. When status was needs_decision with a plan and the user says "Build it" / approve / go ahead, call edit_app with planAction "approve" and omit prompt \u2014 do not put "approve" or "Build it" in prompt (that is refine feedback, not the Build-it path). Use planAction "refine" with their feedback as prompt to change the plan. Also use edit_app to answer multi_choice questions. Returns status "building"; follow with check_app_progress.',
9183
9816
  inputSchema: {
9184
9817
  applicationId: external_exports.string().uuid().optional(),
@@ -9189,7 +9822,7 @@ function createMcpServer(deps) {
9189
9822
  prompt: external_exports.string().min(1).optional()
9190
9823
  },
9191
9824
  title: "Edit App"
9192
- }, async ({ applicationId, branch, idempotencyKey, mode, planAction, prompt }, extra) => run("edit_app", (context2) => editApp(context2, {
9825
+ }, async ({ applicationId, branch, idempotencyKey, mode, planAction, prompt }, extra) => run("edit_app", (context3) => editApp(context3, {
9193
9826
  applicationId,
9194
9827
  branch,
9195
9828
  idempotencyKey: idempotencyKey ?? `mcp-edit:${randomUUID4()}`,
@@ -9199,24 +9832,26 @@ function createMcpServer(deps) {
9199
9832
  wait: "ack"
9200
9833
  }), extra));
9201
9834
  server.registerTool("check_app_progress", {
9835
+ annotations: NON_DESTRUCTIVE_WRITE_TOOL_ANNOTATIONS,
9202
9836
  description: `Wait for the next thing Superblocks does on the recent or specified application and return it: "activity" carries Superblocks' words since the previous call (or a short heartbeat when Superblocks is quiet), and status is "building" while the app is still being generated. Returns as soon as Superblocks says anything, and after ~10 seconds of silence at the latest. Call within about 10 seconds of start_app, import_app, or edit_app so a plan or question surfaces quickly. Once the plan is approved and Superblocks is building, space later polls about 30 seconds apart (honor "nextPollAfterMs" when present) until status is no longer "building" \u2014 a 10-second cadence on a multi-minute build burns through the host's tool-call budget. Relay each new activity line to the user between calls. When status becomes "needs_decision", stop polling and put the decision to the user \u2014 for a plan, show it and ask whether to build it or say what to change; for multi_choice, relay the question and options. Hosts that support form elicitation get a native picker instead, and this tool then returns the answered turn. When status becomes "ready", follow with get_app so the user can open the preview. Progress is text-only (no MCP Apps widget) so each poll does not reopen a blank card. Optional "cursor" from a prior result resumes from that composite position (per producer, no global sequence); omit it to use the gateway's stored place for this caller.`,
9203
9837
  inputSchema: {
9204
9838
  applicationId: external_exports.string().uuid().optional(),
9205
9839
  cursor: eventCursorInputSchema.optional()
9206
9840
  },
9207
9841
  title: "Check App Progress"
9208
- }, async ({ applicationId, cursor }, extra) => run("check_app_progress", (context2, forgetFinishedTurn) => {
9842
+ }, async ({ applicationId, cursor }, extra) => run("check_app_progress", (context3, forgetFinishedTurn) => {
9209
9843
  const parsed = cursor === void 0 ? void 0 : parseEventCursor(cursor);
9210
9844
  gatewayDebug("progress cursor parsed", {
9211
9845
  "progress.cursor_provided": cursor !== void 0,
9212
9846
  "progress.cursor_valid": Boolean(parsed)
9213
9847
  });
9214
- return progressWithDecisionForm(context2, {
9848
+ return progressWithDecisionForm(context3, {
9215
9849
  applicationId,
9216
9850
  ...parsed ? { cursor: parsed } : {}
9217
9851
  }, extra, forgetFinishedTurn);
9218
9852
  }, extra));
9219
9853
  K3(server, "get_app", {
9854
+ annotations: READ_ONLY_TOOL_ANNOTATIONS,
9220
9855
  description: 'Return editor and preview URLs for the recent or specified Superblocks application. Ensures a private preview build by default (same as preview_app), but only once Superblocks has something to show: while a plan or question is outstanding it returns status "needs_decision" with the "decision" and a "pendingAction" of "approve_plan" or "answer_question", while a turn is running it returns status "building", and when the last turn ended without writing anything it returns "timeout", "live_edit_terminated", "no_changes" or "cancelled" with pendingAction "retry_build" \u2014 no preview URLs and no screenshot in any of those cases, because the app is still the empty starter template. Act on "pendingAction" through edit_app instead of calling this again. Prefer this after check_app_progress reaches status "ready". Also the right call when you do not know where a build stands \u2014 after a reconnect, when no turn of yours is running, or when the conversation moved to another channel: pass wait false and read "status" and "cursor" from the result rather than guessing. Hosts that support MCP Apps show Open editor / Open preview buttons. When Superblocks has written code the result includes a screenshot of the live Vite canvas if a held session exists, otherwise the signed-in preview \u2014 never the edit URL.',
9221
9856
  inputSchema: {
9222
9857
  applicationId: external_exports.string().uuid().optional(),
@@ -9228,15 +9863,16 @@ function createMcpServer(deps) {
9228
9863
  _meta: {
9229
9864
  ui: { resourceUri: APP_STATUS_RESOURCE_URI }
9230
9865
  }
9231
- }, async ({ applicationId, branch, ensurePreview, wait }, extra) => run("get_app", (context2) => getApp(context2, { applicationId, branch, ensurePreview, wait }), extra));
9866
+ }, async ({ applicationId, branch, ensurePreview, wait }, extra) => run("get_app", (context3) => getApp(context3, { applicationId, branch, ensurePreview, wait }), extra));
9232
9867
  server.registerTool("preview_app", {
9868
+ annotations: READ_ONLY_TOOL_ANNOTATIONS,
9233
9869
  description: `Build the recent or specified Superblocks application's current work and return a URL that runs it, without deploying it \u2014 the same thing the editor's Preview button does. Only the user can open it. Status "ready" means the URL works now; "building" means the build is still running and calling again resumes watching it. Prefer get_app when you want the MCP Apps status card (Open editor / Open preview); this tool returns the same URLs as text/markdown without opening a second widget.`,
9234
9870
  inputSchema: {
9235
9871
  applicationId: external_exports.string().uuid().optional(),
9236
9872
  branch: external_exports.string().optional()
9237
9873
  },
9238
9874
  title: "Preview App"
9239
- }, async ({ applicationId, branch }, extra) => run("preview_app", (context2) => previewApp(context2, { applicationId, branch }), extra));
9875
+ }, async ({ applicationId, branch }, extra) => run("preview_app", (context3) => previewApp(context3, { applicationId, branch }), extra));
9240
9876
  const uiCsp = { csp: { frameDomains: [] } };
9241
9877
  N3(server, "Gateway app status", APP_STATUS_RESOURCE_URI, {
9242
9878
  description: "Status card with Open editor / Open preview / Publish app",
@@ -9253,6 +9889,7 @@ function createMcpServer(deps) {
9253
9889
  ]
9254
9890
  }));
9255
9891
  server.registerTool("publish_app", {
9892
+ annotations: DESTRUCTIVE_TOOL_ANNOTATIONS,
9256
9893
  description: "Publish/deploy the recent or specified Superblocks application and wait until it is live. Commits the application's current work first, so commitId is only needed to publish an earlier commit.",
9257
9894
  inputSchema: {
9258
9895
  applicationId: external_exports.string().uuid().optional(),
@@ -9262,7 +9899,7 @@ function createMcpServer(deps) {
9262
9899
  prompt: external_exports.string().min(1)
9263
9900
  },
9264
9901
  title: "Publish App"
9265
- }, async ({ applicationId, branch, commitId, idempotencyKey, prompt }, extra) => run("publish_app", (context2) => publishApp(context2, {
9902
+ }, async ({ applicationId, branch, commitId, idempotencyKey, prompt }, extra) => run("publish_app", (context3) => publishApp(context3, {
9266
9903
  applicationId,
9267
9904
  branch,
9268
9905
  commitId,
@@ -9282,6 +9919,7 @@ function createMcpServer(deps) {
9282
9919
  async function createRuntime(apiKey) {
9283
9920
  const config = loadConfig();
9284
9921
  const stores = await createStores();
9922
+ const telemetry = startGatewayTelemetry({ apiKey, config });
9285
9923
  const serverClient = new HttpSuperblocksServerClient(config.serverUrl);
9286
9924
  const sessionPeer = new WebSocketSessionPeer({
9287
9925
  beatLostGraceMs: config.beatLostGraceMs,
@@ -9299,6 +9937,7 @@ async function createRuntime(apiKey) {
9299
9937
  cliApiKey: apiKey,
9300
9938
  config,
9301
9939
  events: stores.events,
9940
+ mcpTelemetry: telemetry.mcpTelemetry,
9302
9941
  progressCursors: stores.progressCursors,
9303
9942
  recentApps: stores.recentApps,
9304
9943
  server: serverClient,
@@ -9310,7 +9949,7 @@ async function createRuntime(apiKey) {
9310
9949
  deps,
9311
9950
  close: async () => {
9312
9951
  sessionPeer.closeAll();
9313
- await stores.close();
9952
+ await Promise.allSettled([stores.close(), telemetry.shutdown()]);
9314
9953
  }
9315
9954
  };
9316
9955
  }
@@ -9356,4 +9995,4 @@ export {
9356
9995
  startApp,
9357
9996
  startStdioGateway
9358
9997
  };
9359
- //# sourceMappingURL=dist-T7YMQ4FI.js.map
9998
+ //# sourceMappingURL=dist-Y4DZZVYZ.js.map