@superblocksteam/gateway 2.0.157 → 2.0.158

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 (40) hide show
  1. package/README.md +30 -3
  2. package/dist/capabilities/integration-metadata.d.ts +28 -0
  3. package/dist/capabilities/integration-metadata.js +174 -0
  4. package/dist/capabilities/integration-metadata.js.map +1 -0
  5. package/dist/capabilities/lifecycle.d.ts +12 -1
  6. package/dist/capabilities/lifecycle.js +99 -51
  7. package/dist/capabilities/lifecycle.js.map +1 -1
  8. package/dist/capabilities/types.d.ts +5 -0
  9. package/dist/capabilities/types.js.map +1 -1
  10. package/dist/deps.d.ts +2 -0
  11. package/dist/integrations/map.d.ts +1 -0
  12. package/dist/integrations/map.js +1 -1
  13. package/dist/integrations/map.js.map +1 -1
  14. package/dist/sabs/editor-client-methods.js +4 -5
  15. package/dist/sabs/editor-client-methods.js.map +1 -1
  16. package/dist/sabs/session-peer.d.ts +4 -0
  17. package/dist/sabs/websocket-session-peer.d.ts +2 -1
  18. package/dist/sabs/websocket-session-peer.js +21 -11
  19. package/dist/sabs/websocket-session-peer.js.map +1 -1
  20. package/dist/server/client.d.ts +10 -4
  21. package/dist/server/client.js +13 -4
  22. package/dist/server/client.js.map +1 -1
  23. package/dist/start.d.ts +10 -0
  24. package/dist/start.js +5 -2
  25. package/dist/start.js.map +1 -1
  26. package/dist/telemetry/mcp-client.d.ts +22 -0
  27. package/dist/telemetry/mcp-client.js +129 -0
  28. package/dist/telemetry/mcp-client.js.map +1 -0
  29. package/dist/telemetry/runtime.d.ts +9 -0
  30. package/dist/telemetry/runtime.js +121 -0
  31. package/dist/telemetry/runtime.js.map +1 -0
  32. package/dist/transports/mcp/admin-tools.d.ts +3 -1
  33. package/dist/transports/mcp/admin-tools.js +12 -1
  34. package/dist/transports/mcp/admin-tools.js.map +1 -1
  35. package/dist/transports/mcp/app-status-html.d.ts +2 -2
  36. package/dist/transports/mcp/app-status-html.js +139 -8
  37. package/dist/transports/mcp/app-status-html.js.map +1 -1
  38. package/dist/transports/mcp/mount.js +89 -24
  39. package/dist/transports/mcp/mount.js.map +1 -1
  40. package/package.json +5 -4
@@ -0,0 +1,129 @@
1
+ import { context, SpanStatusCode, trace, } from "@opentelemetry/api";
2
+ function bounded(value, maxLength) {
3
+ return value.slice(0, maxLength);
4
+ }
5
+ function stringProperty(value, key) {
6
+ if (typeof value !== "object" || value === null || !(key in value)) {
7
+ return undefined;
8
+ }
9
+ const property = Reflect.get(value, key);
10
+ return typeof property === "string" ? property : undefined;
11
+ }
12
+ export class McpClientTelemetry {
13
+ tracer;
14
+ ended = false;
15
+ hadError = false;
16
+ organizationId;
17
+ sessionContext;
18
+ sessionSpan;
19
+ constructor(tracer) {
20
+ this.tracer = tracer;
21
+ this.sessionSpan = tracer.startSpan("gen_ai.request", {
22
+ attributes: {
23
+ "gen_ai.operation.name": "invoke_agent",
24
+ },
25
+ });
26
+ this.sessionContext = trace.setSpan(context.active(), this.sessionSpan);
27
+ }
28
+ setOrganizationId(organizationId) {
29
+ this.organizationId = organizationId;
30
+ this.sessionSpan.setAttribute("organization.id", organizationId);
31
+ }
32
+ async runTool(call, operation) {
33
+ const attributes = {
34
+ "gen_ai.operation.name": "execute_tool",
35
+ ...(call.client
36
+ ? {
37
+ "mcp.client.name": bounded(call.client.name, 80),
38
+ ...(call.client.version
39
+ ? {
40
+ "mcp.client.version": bounded(call.client.version, 40),
41
+ }
42
+ : {}),
43
+ }
44
+ : {}),
45
+ ...(this.organizationId
46
+ ? { "organization.id": this.organizationId }
47
+ : {}),
48
+ "tool.name": bounded(call.toolName, 80),
49
+ };
50
+ if (call.client) {
51
+ this.sessionSpan.setAttributes({
52
+ "mcp.client.name": bounded(call.client.name, 80),
53
+ ...(call.client.version
54
+ ? { "mcp.client.version": bounded(call.client.version, 40) }
55
+ : {}),
56
+ });
57
+ }
58
+ let span;
59
+ try {
60
+ span = this.tracer.startSpan("gen_ai.tool_call", { attributes }, this.sessionContext);
61
+ }
62
+ catch {
63
+ return operation();
64
+ }
65
+ const startedAt = Date.now();
66
+ try {
67
+ const result = await context.with(trace.setSpan(this.sessionContext, span), operation);
68
+ span.setAttribute("tool.duration_ms", Date.now() - startedAt);
69
+ if (this.organizationId) {
70
+ span.setAttribute("organization.id", this.organizationId);
71
+ }
72
+ if (result.kind === "error") {
73
+ this.hadError = true;
74
+ span.setAttributes({
75
+ ...(result.applicationId
76
+ ? { "application.id": result.applicationId }
77
+ : {}),
78
+ "mcp.error.code": bounded(result.code, 80),
79
+ "tool.error_category": result.code === "cancelled" ? "timeout" : "execution_error",
80
+ "tool.status": "error",
81
+ });
82
+ span.setStatus({ code: SpanStatusCode.ERROR });
83
+ }
84
+ else if (result.kind === "auth_required") {
85
+ this.hadError = true;
86
+ span.setAttributes({
87
+ "mcp.result.status": "auth_required",
88
+ "tool.error_category": "permission_denied",
89
+ "tool.status": "error",
90
+ });
91
+ }
92
+ else {
93
+ const applicationId = stringProperty(result.value, "applicationId");
94
+ const resultStatus = stringProperty(result.value, "status");
95
+ span.setAttributes({
96
+ ...(applicationId ? { "application.id": applicationId } : {}),
97
+ ...(resultStatus
98
+ ? { "mcp.result.status": bounded(resultStatus, 80) }
99
+ : {}),
100
+ "tool.error_category": "none",
101
+ "tool.status": "success",
102
+ });
103
+ }
104
+ return result;
105
+ }
106
+ catch (error) {
107
+ this.hadError = true;
108
+ span.setAttributes({
109
+ "tool.duration_ms": Date.now() - startedAt,
110
+ "tool.error_category": "execution_error",
111
+ "tool.status": "error",
112
+ });
113
+ span.setStatus({ code: SpanStatusCode.ERROR });
114
+ throw error;
115
+ }
116
+ finally {
117
+ span.end();
118
+ }
119
+ }
120
+ endSession() {
121
+ if (this.ended) {
122
+ return;
123
+ }
124
+ this.ended = true;
125
+ this.sessionSpan.setAttribute("gen_ai.request.status", this.hadError ? "error" : "success");
126
+ this.sessionSpan.end();
127
+ }
128
+ }
129
+ //# sourceMappingURL=mcp-client.js.map
@@ -0,0 +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I,CAAC,WAAW,CAAC,YAAY,CAC3B,uBAAuB,EACvB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CACpC,CAAC;QACF,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import type { GatewayConfig } from "../config.js";
2
+ import { McpClientTelemetry } from "./mcp-client.js";
3
+ export declare function startGatewayTelemetry(input: {
4
+ apiKey: string;
5
+ config: GatewayConfig;
6
+ }): {
7
+ mcpTelemetry: McpClientTelemetry;
8
+ shutdown: () => Promise<void>;
9
+ };
@@ -0,0 +1,121 @@
1
+ import { DeploymentType, getDefaultPolicy, parseDeploymentType, } from "@superblocksteam/telemetry";
2
+ import { initNodeTelemetry } from "@superblocksteam/telemetry/node";
3
+ import { McpClientTelemetry } from "./mcp-client.js";
4
+ const TELEMETRY_SHUTDOWN_MS = 2_000;
5
+ /**
6
+ * stdout is the MCP JSON-RPC wire. Without a logger the shared init falls back
7
+ * to console.info, which writes there and corrupts the protocol.
8
+ */
9
+ function logToStderr(first, message) {
10
+ if (message === undefined) {
11
+ console.error(first);
12
+ return;
13
+ }
14
+ console.error(first, message);
15
+ }
16
+ const stderrLogger = {
17
+ error: logToStderr,
18
+ info: logToStderr,
19
+ warn: logToStderr,
20
+ };
21
+ function telemetryBaseUrl(serverUrl) {
22
+ try {
23
+ const url = new URL(serverUrl);
24
+ url.hash = "";
25
+ url.pathname = `${url.pathname.replace(/\/$/u, "")}/api`;
26
+ url.search = "";
27
+ return url.toString().replace(/\/$/u, "");
28
+ }
29
+ catch {
30
+ console.error("gateway telemetry skipped: server URL is not parseable");
31
+ return undefined;
32
+ }
33
+ }
34
+ function environmentName(config) {
35
+ if (config.deploymentEnvironmentName !== "unknown") {
36
+ return config.deploymentEnvironmentName;
37
+ }
38
+ try {
39
+ return environmentFromHostname(new URL(config.serverUrl).hostname);
40
+ }
41
+ catch {
42
+ return "unknown";
43
+ }
44
+ }
45
+ function environmentFromHostname(hostname) {
46
+ if (hostname.match(/^app\.superblocks(?:hq)?\.com$/u)) {
47
+ return "prod";
48
+ }
49
+ if (hostname.match(/^eu\.superblocks(?:hq)?\.com$/u)) {
50
+ return "prod-eu";
51
+ }
52
+ if (hostname.match(/^staging\.superblocks(?:hq)?\.com$/u)) {
53
+ return "staging";
54
+ }
55
+ if (hostname.match(/^dev\.superblocks(?:hq)?\.com$/u)) {
56
+ return "dev";
57
+ }
58
+ if (hostname.match(/^pr-[0-9]+\.superblocks(?:hq)?\.dev$/u)) {
59
+ return "ephemeral";
60
+ }
61
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
62
+ return "local";
63
+ }
64
+ return "other";
65
+ }
66
+ function deploymentTypeFor(config) {
67
+ if (config.localAgentMode) {
68
+ return DeploymentType.CLOUD_PREM;
69
+ }
70
+ try {
71
+ return parseDeploymentType(process.env.SUPERBLOCKS_DEPLOYMENT_TYPE);
72
+ }
73
+ catch {
74
+ return DeploymentType.CLOUD;
75
+ }
76
+ }
77
+ async function settleWithin(work, timeoutMs) {
78
+ let timer;
79
+ try {
80
+ await Promise.race([
81
+ work,
82
+ new Promise((resolve) => {
83
+ timer = setTimeout(resolve, timeoutMs);
84
+ }),
85
+ ]);
86
+ }
87
+ finally {
88
+ if (timer !== undefined) {
89
+ clearTimeout(timer);
90
+ }
91
+ }
92
+ }
93
+ export function startGatewayTelemetry(input) {
94
+ const otlpUrl = telemetryBaseUrl(input.config.serverUrl);
95
+ const telemetry = initNodeTelemetry({
96
+ environment: environmentName(input.config),
97
+ logger: stderrLogger,
98
+ logsEnabled: false,
99
+ // Counters in metrics.ts are created at import time, before this SDK
100
+ // starts, so they stay no-ops. Do not turn metrics on until those
101
+ // instruments are created after init.
102
+ metricsEnabled: false,
103
+ otlpHeaders: { Authorization: `Bearer ${input.apiKey}` },
104
+ ...(otlpUrl ? { otlpUrl } : {}),
105
+ serviceName: "gateway",
106
+ serviceVersion: "0.0.1",
107
+ }, getDefaultPolicy(deploymentTypeFor(input.config)));
108
+ const mcpTelemetry = new McpClientTelemetry(telemetry.getTracer("gateway.mcp"));
109
+ return {
110
+ mcpTelemetry,
111
+ shutdown: async () => {
112
+ try {
113
+ mcpTelemetry.endSession();
114
+ }
115
+ finally {
116
+ await settleWithin(telemetry.shutdown(), TELEMETRY_SHUTDOWN_MS);
117
+ }
118
+ },
119
+ };
120
+ }
121
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/telemetry/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;;GAGG;AACH,SAAS,WAAW,CAAC,KAAsB,EAAE,OAAgB;IAC3D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,WAAW;CAClB,CAAC;AAEF,SAAS,gBAAgB,CAAC,SAAiB;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;QACzD,GA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AAE,SAAS;QACtB,cAAc,EAAE,OAAO;KACxB,EACD,gBAAgB,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAClD,CAAC;IACF,MAAM,YAAY,GAAG,IAAI,kBAAkB,CACzC,SAAS,CAAC,SAAS,CAAC,aAAa,CAAC,CACnC,CAAC;IAEF,OAAO;QACL,YAAY;QACZ,QAAQ,EAAE,KAAK,IAAI,EAAE;YACnB,IAAI,CAAC;gBACH,YAAY,CAAC,UAAU,EAAE,CAAC;YAC5B,CAAC;oBAAS,CAAC;gBACT,MAAM,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,qBAAqB,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
2
2
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import type { Tool } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { Tool, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
4
4
  import { z } from "zod";
5
5
  import { type ToolRegistry } from "@superblocksteam/mcp-server";
6
6
  export type RegisterAdminToolsOptions = {
@@ -39,6 +39,8 @@ export declare function jsonSchemaToZodShape(inputSchema: Tool["inputSchema"], o
39
39
  * so clients do not reintroduce that name.
40
40
  */
41
41
  export declare function superblocksProductCopy(text: string): string;
42
+ /** Completes MCP hints without overriding shared Admin definitions. */
43
+ export declare function completeToolAnnotations(annotations: ToolAnnotations | undefined): ToolAnnotations;
42
44
  /**
43
45
  * Registers customer-profile Admin MCP tools on the same McpServer as Builder
44
46
  * tools. Each call runs under `runWithAuthContext` with the Gateway's
@@ -107,6 +107,17 @@ export function superblocksProductCopy(text) {
107
107
  .replaceAll(/\bClark AI Apps\b/g, "Superblocks AI Apps")
108
108
  .replaceAll(/\bClark\b/g, "Superblocks");
109
109
  }
110
+ /** Completes MCP hints without overriding shared Admin definitions. */
111
+ export function completeToolAnnotations(annotations) {
112
+ const readOnlyHint = annotations?.readOnlyHint ?? false;
113
+ return {
114
+ ...annotations,
115
+ destructiveHint: annotations?.destructiveHint ?? (readOnlyHint ? false : true),
116
+ idempotentHint: annotations?.idempotentHint ?? readOnlyHint,
117
+ openWorldHint: annotations?.openWorldHint ?? true,
118
+ readOnlyHint,
119
+ };
120
+ }
110
121
  /**
111
122
  * Registers customer-profile Admin MCP tools on the same McpServer as Builder
112
123
  * tools. Each call runs under `runWithAuthContext` with the Gateway's
@@ -122,7 +133,7 @@ export function registerAdminTools(server, options) {
122
133
  }
123
134
  const definition = toolDefinitions.find((d) => d.name === tool.name);
124
135
  server.registerTool(tool.name, {
125
- annotations: tool.annotations,
136
+ annotations: completeToolAnnotations(tool.annotations),
126
137
  description: superblocksProductCopy(tool.description ?? ""),
127
138
  inputSchema: gatewayAdminInputShape(tool.inputSchema),
128
139
  title: tool.title ?? definition?.title,
@@ -1 +1 @@
1
- {"version":3,"file":"admin-tools.js","sourceRoot":"","sources":["../../../src/transports/mcp/admin-tools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,GAEhB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAyCjE;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,WAAgC,EAChC,UAAuC,EAAE;IAEzC,MAAM,UAAU,GACb,WAAW,EAAE,UAEA,IAAI,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;IACtD,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,YAAY,IAAI,EAAE,EAAE,CAAC;QAC7C,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;I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AAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;oBAChE,aAAa,EAAE,OAAO;oBACtB,WAAW,EAAE,IAAI,CAAC,IAAI;iBACvB,CAAC,CAAC;gBACH,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -11,5 +11,5 @@
11
11
  * card (hosts cache UI resources; keep this file small and inline). Bump the
12
12
  * resource URI when the HTML changes so Claude Desktop refreshes its cache.
13
13
  */
14
- export declare const APP_STATUS_RESOURCE_URI = "ui://gateway/app-status-v6.html";
15
- export declare const APP_STATUS_HTML = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>Superblocks app</title>\n <style>\n :root {\n color-scheme: light dark;\n }\n body {\n margin: 0;\n font-family: var(--font-sans, system-ui, -apple-system, sans-serif);\n font-size: var(--font-text-sm-size, 13px);\n line-height: var(--font-text-sm-line-height, 1.45);\n color: var(--color-text-primary, #0f172a);\n background: transparent;\n }\n .card {\n display: flex;\n flex-direction: column;\n gap: 10px;\n padding: 14px;\n border: var(--border-width-regular, 1px) solid\n var(--color-border-primary, #e2e8f0);\n border-radius: var(--border-radius-lg, 12px);\n background: var(--color-background-primary, #ffffff);\n }\n .head {\n display: flex;\n align-items: center;\n gap: 8px;\n }\n h1 {\n flex: 1;\n margin: 0;\n font-size: var(--font-text-md-size, 14px);\n font-weight: var(--font-weight-semibold, 600);\n }\n .status {\n padding: 2px 8px;\n border-radius: var(--border-radius-full, 999px);\n background: var(--color-background-secondary, #f1f5f9);\n color: var(--color-text-secondary, #64748b);\n font-size: var(--font-text-xs-size, 12px);\n text-transform: lowercase;\n }\n .meta {\n color: var(--color-text-tertiary, #94a3b8);\n font-size: var(--font-text-xs-size, 12px);\n }\n .note {\n display: none;\n color: var(--color-text-warning, #b45309);\n font-size: var(--font-text-xs-size, 12px);\n }\n .note.shown {\n display: block;\n }\n .shot {\n display: none;\n width: 100%;\n border: var(--border-width-regular, 1px) solid\n var(--color-border-primary, #e2e8f0);\n border-radius: var(--border-radius-md, 8px);\n }\n .shot.shown {\n display: block;\n }\n .actions {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n }\n button {\n appearance: none;\n border: var(--border-width-regular, 1px) solid\n var(--color-border-primary, #e2e8f0);\n border-radius: var(--border-radius-md, 8px);\n padding: 7px 12px;\n background: var(--color-background-secondary, #f8fafc);\n color: var(--color-text-primary, #0f172a);\n font: inherit;\n font-weight: var(--font-weight-medium, 500);\n cursor: pointer;\n }\n button:hover:not(:disabled) {\n background: var(--color-background-tertiary, #f1f5f9);\n }\n button:disabled {\n opacity: 0.45;\n cursor: not-allowed;\n }\n </style>\n</head>\n<body>\n <div class=\"card\">\n <div class=\"head\">\n <h1>Superblocks app</h1>\n <span id=\"status\" class=\"status\">loading</span>\n </div>\n <div id=\"appId\" class=\"meta\"></div>\n <img id=\"shot\" class=\"shot\" alt=\"Preview of the running app\" />\n <div id=\"note\" class=\"note\"></div>\n <div class=\"actions\">\n <button id=\"openEditor\" type=\"button\" disabled>Open editor</button>\n <button id=\"openPreview\" type=\"button\" disabled>Open preview</button>\n <button id=\"publishApp\" type=\"button\" disabled>Publish app</button>\n </div>\n </div>\n <script>\n (() => {\n const PROTOCOL_VERSION = \"2026-01-26\";\n let nextId = 1;\n const pending = new Map();\n let applicationId = \"\";\n let appName = \"\";\n let commitId = \"\";\n let editUrl = \"\";\n let previewUrl = \"\";\n let publishUrl = \"\";\n let canOpenLinks = false;\n let canCallTools = false;\n let publishing = false;\n let lastHeight = 0;\n\n function post(message) {\n window.parent.postMessage(message, \"*\");\n }\n\n function notify(method, params) {\n post({ jsonrpc: \"2.0\", method, params });\n }\n\n function request(method, params) {\n const id = nextId++;\n return new Promise((resolve, reject) => {\n pending.set(id, { resolve, reject });\n post({ jsonrpc: \"2.0\", id, method, params });\n });\n }\n\n function element(id) {\n return document.getElementById(id);\n }\n\n function show(id, on) {\n const node = element(id);\n if (node && node.classList) {\n node.classList.toggle(\"shown\", on);\n }\n }\n\n // Hosts size the card from this notification alone; without it the card\n // is laid out at zero height and never appears.\n function reportSize() {\n const height = Math.ceil(document.documentElement.scrollHeight || 0);\n if (height <= 0 || height === lastHeight) {\n return;\n }\n lastHeight = height;\n notify(\"ui/notifications/size-changed\", {\n height,\n width: Math.ceil(window.innerWidth || 0),\n });\n }\n\n function note(text) {\n element(\"note\").textContent = text;\n show(\"note\", Boolean(text));\n reportSize();\n }\n\n function isPlainHttp(url) {\n return url.slice(0, 5).toLowerCase() === \"http:\";\n }\n\n /** A UUID says nothing; the name the user asked Superblocks for does. */\n function renderIdentity() {\n element(\"appId\").textContent = appName || applicationId;\n }\n\n /**\n * Draws the screenshot the tool captured.\n *\n * Hosts that render an MCP App render it *instead of* the tool's content\n * blocks, so the image block get_app returns never reaches the user on\n * its own \u2014 the card has to take it out of the result and show it.\n */\n function showScreenshot(dataBase64, mimeType) {\n if (typeof dataBase64 !== \"string\" || !dataBase64) {\n return;\n }\n element(\"shot\").src =\n \"data:\" + (mimeType || \"image/jpeg\") + \";base64,\" + dataBase64;\n show(\"shot\", true);\n reportSize();\n }\n\n /** Applies every part of an MCP content array the card understands. */\n function applyContent(content) {\n for (const part of content || []) {\n if (!part) {\n continue;\n }\n if (part.type === \"text\" && typeof part.text === \"string\") {\n applyPayload(part.text);\n }\n if (part.type === \"image\") {\n showScreenshot(part.data, part.mimeType);\n }\n }\n }\n\n /**\n * Keep URLs in memory for openLink \u2014 never print them (preview JWTs are\n * huge and ugly in the card).\n */\n function renderActions() {\n element(\"openEditor\").disabled = !editUrl || !canOpenLinks;\n element(\"openPreview\").disabled = !previewUrl || !canOpenLinks;\n // Once the app is live, publishing again is not what anyone wants from\n // this button \u2014 going to the live app is.\n element(\"publishApp\").textContent = publishUrl\n ? \"Open published app\"\n : \"Publish app\";\n element(\"publishApp\").disabled = publishUrl\n ? !canOpenLinks\n : !applicationId || !canCallTools || publishing;\n // Only warn about what is actually broken. Hosts that do open links\n // handle local http fine; if one refuses, refused() says so then.\n if (!canOpenLinks && (editUrl || previewUrl) && !publishUrl) {\n note(\"This host cannot open links for me \u2014 ask the model for an https preview URL.\");\n }\n reportSize();\n }\n\n /** Only ever ask the host to open a real web address. */\n function webUrl(candidate) {\n try {\n const parsed = new URL(candidate);\n return parsed.protocol === \"http:\" || parsed.protocol === \"https:\"\n ? candidate\n : \"\";\n } catch {\n return \"\";\n }\n }\n\n /**\n * Merges whatever the host sent. Hosts replay tool input as well as tool\n * results, and the input carries no status or URLs \u2014 overwriting from a\n * partial payload is what showed the card as \"unknown\".\n *\n * Hosts also disagree on the shape: some pass the capability JSON, some\n * pass the MCP content/text envelope (Claude Desktop on initialize), and\n * some nest that under structuredContent.\n */\n function applyPayload(raw) {\n let data = raw;\n if (typeof raw === \"string\") {\n try {\n data = JSON.parse(raw);\n } catch {\n return;\n }\n }\n if (!data || typeof data !== \"object\") {\n return;\n }\n // MCP tool-result / initialize toolResult envelope.\n if (Array.isArray(data.content)) {\n applyContent(data.content);\n if (data.structuredContent) {\n applyPayload(data.structuredContent);\n }\n return;\n }\n if (data.result && typeof data.result === \"object\") {\n applyPayload(data.result);\n return;\n }\n const value = data.kind === \"ok\" ? data.value : data;\n if (!value || typeof value !== \"object\") {\n return;\n }\n if (typeof value.status === \"string\") {\n element(\"status\").textContent = value.status;\n }\n if (typeof value.applicationId === \"string\") {\n applicationId = value.applicationId;\n renderIdentity();\n }\n if (typeof value.name === \"string\" && value.name) {\n appName = value.name;\n renderIdentity();\n }\n if (typeof value.commitId === \"string\") {\n commitId = value.commitId;\n }\n if (typeof value.screenshotBase64 === \"string\") {\n showScreenshot(value.screenshotBase64, \"image/jpeg\");\n }\n if (typeof value.editUrl === \"string\") {\n editUrl = webUrl(value.editUrl);\n }\n if (typeof value.previewUrl === \"string\") {\n previewUrl = webUrl(value.previewUrl);\n }\n if (typeof value.publishUrl === \"string\") {\n publishUrl = webUrl(value.publishUrl);\n }\n // Hosts that deliver URLs without a status left the badge on the HTML\n // default (\"loading\") even after the app was built.\n const badge = element(\"status\").textContent;\n if (\n !value.status &&\n editUrl &&\n (badge === \"\" || badge === \"loading\" || badge === \"waiting\")\n ) {\n element(\"status\").textContent = previewUrl ? \"ready\" : \"building\";\n }\n renderActions();\n }\n\n /**\n * When the host opened the card with tool input (applicationId) but never\n * pushed a tool result, refresh ourselves so the badge is not stuck on\n * \"loading\" after the build finished.\n */\n function refreshFromServer() {\n if (!canCallTools || !applicationId || editUrl) {\n return;\n }\n request(\"tools/call\", {\n name: \"get_app\",\n arguments: { applicationId },\n })\n .then((result) => {\n if (!result || result.isError) {\n return;\n }\n applyPayload(result);\n if (result.structuredContent) {\n applyPayload(result.structuredContent);\n }\n })\n .catch(() => {\n // Host declined; stay on whatever we have.\n });\n }\n\n function applyHostContext(context) {\n if (!context || typeof context !== \"object\") {\n return;\n }\n const variables = context.styles && context.styles.variables;\n const style = document.documentElement.style;\n if (variables && style && typeof style.setProperty === \"function\") {\n for (const name of Object.keys(variables)) {\n const value = variables[name];\n if (typeof value === \"string\") {\n style.setProperty(name, value);\n }\n }\n }\n reportSize();\n }\n\n function refused(url) {\n note(\n isPlainHttp(url)\n ? \"This host only opens https links, and this app is served over http \u2014 ask for an https preview URL.\"\n : \"The host could not open the link \u2014 try again or ask the model for another URL.\",\n );\n }\n\n function openLink(url) {\n if (!url || !canOpenLinks) {\n return;\n }\n request(\"ui/open-link\", { url })\n .then((result) => {\n if (result && result.isError) {\n refused(url);\n return;\n }\n note(\"\");\n })\n .catch(() => refused(url));\n }\n\n /**\n * Asks the host to proxy publish_app back to this MCP server. The prompt\n * is the commit message createCommit needs; the card supplies a fixed one\n * so the user does not have to type through the model.\n */\n function publish() {\n if (!applicationId || !canCallTools || publishing) {\n return;\n }\n publishing = true;\n renderActions();\n note(\"Publishing\u2026\");\n const args = {\n applicationId,\n idempotencyKey:\n \"mcp-app-publish:\" + applicationId + \":\" + Date.now(),\n prompt: \"Published from Gateway status card\",\n };\n if (commitId) {\n args.commitId = commitId;\n }\n request(\"tools/call\", { name: \"publish_app\", arguments: args })\n .then((result) => {\n publishing = false;\n if (!result || result.isError) {\n const text =\n result &&\n Array.isArray(result.content) &&\n result.content[0] &&\n result.content[0].text\n ? String(result.content[0].text)\n : \"Publish failed.\";\n note(text.slice(0, 280));\n renderActions();\n return;\n }\n applyContent(result.content || []);\n if (result.structuredContent) {\n applyPayload(result.structuredContent);\n }\n note(\n publishUrl\n ? \"Published \u2014 open the live app with Open published app.\"\n : \"Published \u2014 the app is live.\",\n );\n renderActions();\n })\n .catch((error) => {\n publishing = false;\n note(\n (error && error.message) ||\n \"The host could not call publish_app.\",\n );\n renderActions();\n });\n }\n\n function handleHostMessage(event) {\n // App documents are opaque-origin, so the host window is the only\n // identity available to authenticate a message against.\n if (event.source !== window.parent) {\n return;\n }\n const data = event.data;\n if (!data || typeof data !== \"object\") {\n return;\n }\n if (data.method === \"ping\") {\n post({ jsonrpc: \"2.0\", id: data.id, result: {} });\n return;\n }\n if (data.id != null && pending.has(data.id)) {\n const waiter = pending.get(data.id);\n pending.delete(data.id);\n if (data.error) {\n waiter.reject(data.error);\n } else {\n waiter.resolve(data.result);\n }\n return;\n }\n const method = data.method;\n const params = data.params || {};\n if (\n method === \"ui/notifications/tool-result\" ||\n method === \"ui/tool-result\" ||\n method === \"tools/call\"\n ) {\n applyContent(params.content || params.result?.content || []);\n if (params.structuredContent) {\n applyPayload(params.structuredContent);\n }\n }\n if (method === \"ui/notifications/tool-input\" && params.arguments) {\n applyPayload(params.arguments);\n refreshFromServer();\n }\n if (method === \"ui/notifications/host-context-changed\") {\n applyHostContext(params);\n }\n }\n\n window.addEventListener(\"message\", handleHostMessage);\n\n element(\"openEditor\").addEventListener(\"click\", () => openLink(editUrl));\n element(\"openPreview\").addEventListener(\"click\", () =>\n openLink(previewUrl),\n );\n element(\"publishApp\").addEventListener(\"click\", () => {\n if (publishUrl) {\n openLink(publishUrl);\n return;\n }\n publish();\n });\n\n if (typeof ResizeObserver === \"function\") {\n new ResizeObserver(reportSize).observe(document.documentElement);\n }\n\n void request(\"ui/initialize\", {\n appCapabilities: {\n availableDisplayModes: [\"inline\"],\n },\n appInfo: { name: \"gateway-app-status\", version: \"0.0.6\" },\n protocolVersion: PROTOCOL_VERSION,\n })\n .then((result) => {\n // Hosts hold back tool results until the app confirms it is ready.\n notify(\"ui/notifications/initialized\", {});\n // Buttons that cannot work are worse than no buttons: hosts without\n // openLinks silently drop ui/open-link.\n canOpenLinks = Boolean(\n result && result.hostCapabilities && result.hostCapabilities.openLinks,\n );\n canCallTools = Boolean(\n result &&\n result.hostCapabilities &&\n result.hostCapabilities.serverTools,\n );\n applyHostContext(result && result.hostContext);\n renderActions();\n if (result && result.toolResult) {\n applyPayload(result.toolResult);\n }\n refreshFromServer();\n })\n .catch(() => {\n // Hosts that push tool results via notification still work.\n })\n .finally(reportSize);\n })();\n </script>\n</body>\n</html>\n";
14
+ export declare const APP_STATUS_RESOURCE_URI = "ui://gateway/app-status-v8.html";
15
+ export declare const APP_STATUS_HTML = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>Superblocks app</title>\n <style>\n :root {\n color-scheme: light dark;\n }\n body {\n margin: 0;\n font-family: var(--font-sans, system-ui, -apple-system, sans-serif);\n font-size: var(--font-text-sm-size, 13px);\n line-height: var(--font-text-sm-line-height, 1.45);\n color: var(--color-text-primary, #0f172a);\n background: transparent;\n }\n .card {\n display: flex;\n flex-direction: column;\n gap: 10px;\n padding: 14px;\n border: var(--border-width-regular, 1px) solid\n var(--color-border-primary, #e2e8f0);\n border-radius: var(--border-radius-lg, 12px);\n background: var(--color-background-primary, #ffffff);\n }\n .head {\n display: flex;\n align-items: center;\n gap: 8px;\n }\n h1 {\n flex: 1;\n margin: 0;\n font-size: var(--font-text-md-size, 14px);\n font-weight: var(--font-weight-semibold, 600);\n }\n .status {\n padding: 2px 8px;\n border-radius: var(--border-radius-full, 999px);\n background: var(--color-background-secondary, #f1f5f9);\n color: var(--color-text-secondary, #64748b);\n font-size: var(--font-text-xs-size, 12px);\n text-transform: lowercase;\n }\n .meta {\n color: var(--color-text-tertiary, #94a3b8);\n font-size: var(--font-text-xs-size, 12px);\n }\n .note {\n display: none;\n color: var(--color-text-warning, #b45309);\n font-size: var(--font-text-xs-size, 12px);\n }\n .note.shown {\n display: block;\n }\n .shot {\n display: none;\n width: 100%;\n border: var(--border-width-regular, 1px) solid\n var(--color-border-primary, #e2e8f0);\n border-radius: var(--border-radius-md, 8px);\n }\n .shot.shown {\n display: block;\n }\n .actions {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n }\n button {\n appearance: none;\n border: var(--border-width-regular, 1px) solid\n var(--color-border-primary, #e2e8f0);\n border-radius: var(--border-radius-md, 8px);\n padding: 7px 12px;\n background: var(--color-background-secondary, #f8fafc);\n color: var(--color-text-primary, #0f172a);\n font: inherit;\n font-weight: var(--font-weight-medium, 500);\n cursor: pointer;\n }\n button:hover:not(:disabled) {\n background: var(--color-background-tertiary, #f1f5f9);\n }\n button:disabled {\n opacity: 0.45;\n cursor: not-allowed;\n }\n </style>\n</head>\n<body>\n <div class=\"card\">\n <div class=\"head\">\n <h1>Superblocks app</h1>\n <span id=\"status\" class=\"status\">loading</span>\n </div>\n <div id=\"appId\" class=\"meta\"></div>\n <img id=\"shot\" class=\"shot\" alt=\"Preview of the running app\" />\n <div id=\"note\" class=\"note\"></div>\n <div class=\"actions\">\n <button id=\"openEditor\" type=\"button\" disabled>Open editor</button>\n <button id=\"openPreview\" type=\"button\" disabled>Open preview</button>\n <button id=\"publishApp\" type=\"button\" disabled>Publish app</button>\n </div>\n </div>\n <script>\n (() => {\n const PROTOCOL_VERSION = \"2026-01-26\";\n // Statuses get_app reports when the app is still the empty starter\n // template. \"building\" is deliberately absent: the card only hears a\n // build finished if a new result arrives, so a stale badge would strand\n // the button.\n const UNBUILT_STATUSES = [\n \"cancelled\",\n \"live_edit_terminated\",\n \"needs_decision\",\n \"no_changes\",\n \"timeout\",\n ];\n const BLOCKED_ACTIONS = [\n \"answer_question\",\n \"approve_plan\",\n \"retry_build\",\n \"retry_import\",\n ];\n let nextId = 1;\n const pending = new Map();\n let applicationId = \"\";\n let appName = \"\";\n let commitId = \"\";\n let pendingAction = \"\";\n let editUrl = \"\";\n let previewUrl = \"\";\n let publishUrl = \"\";\n let canOpenLinks = false;\n let canCallTools = false;\n let publishing = false;\n let lastHeight = 0;\n let refreshInFlight = false;\n let refreshTimer = 0;\n let refreshGeneration = 0;\n let refreshAttempts = 0;\n let pollAfterMs = 2000;\n const MIN_POLL_MS = 2000;\n const MAX_REFRESH_ATTEMPTS = 40;\n\n function post(message) {\n window.parent.postMessage(message, \"*\");\n }\n\n function notify(method, params) {\n post({ jsonrpc: \"2.0\", method, params });\n }\n\n function request(method, params) {\n const id = nextId++;\n return new Promise((resolve, reject) => {\n pending.set(id, { resolve, reject });\n post({ jsonrpc: \"2.0\", id, method, params });\n });\n }\n\n function element(id) {\n return document.getElementById(id);\n }\n\n function show(id, on) {\n const node = element(id);\n if (node && node.classList) {\n node.classList.toggle(\"shown\", on);\n }\n }\n\n // Hosts size the card from this notification alone; without it the card\n // is laid out at zero height and never appears.\n function reportSize() {\n const height = Math.ceil(document.documentElement.scrollHeight || 0);\n if (height <= 0 || height === lastHeight) {\n return;\n }\n lastHeight = height;\n notify(\"ui/notifications/size-changed\", {\n height,\n width: Math.ceil(window.innerWidth || 0),\n });\n }\n\n function note(text) {\n element(\"note\").textContent = text;\n show(\"note\", Boolean(text));\n reportSize();\n }\n\n function isPlainHttp(url) {\n return url.slice(0, 5).toLowerCase() === \"http:\";\n }\n\n /** A UUID says nothing; the name the user asked Superblocks for does. */\n function renderIdentity() {\n element(\"appId\").textContent = appName || applicationId;\n }\n\n /**\n * Draws the screenshot the tool captured.\n *\n * Hosts that render an MCP App render it *instead of* the tool's content\n * blocks, so the image block get_app returns never reaches the user on\n * its own \u2014 the card has to take it out of the result and show it.\n */\n function showScreenshot(dataBase64, mimeType) {\n if (typeof dataBase64 !== \"string\" || !dataBase64) {\n return;\n }\n element(\"shot\").src =\n \"data:\" + (mimeType || \"image/jpeg\") + \";base64,\" + dataBase64;\n show(\"shot\", true);\n reportSize();\n }\n\n /** Applies every part of an MCP content array the card understands. */\n function applyContent(content) {\n for (const part of content || []) {\n if (!part) {\n continue;\n }\n if (part.type === \"text\" && typeof part.text === \"string\") {\n applyPayload(part.text);\n }\n if (part.type === \"image\") {\n showScreenshot(part.data, part.mimeType);\n }\n }\n }\n\n /**\n * True when publishing would deploy the empty starter template.\n * pendingAction is the server's own \"nothing to preview\" signal;\n * wait_for_build is the building exception. Status is only a fallback\n * when the payload omitted pendingAction. loading/waiting with no\n * preview fail closed so Publish is not clickable before get_app\n * returns.\n */\n function nothingToPublish() {\n if (previewUrl || publishUrl) {\n return false;\n }\n if (pendingAction === \"wait_for_build\") {\n return false;\n }\n if (BLOCKED_ACTIONS.indexOf(pendingAction) !== -1) {\n return true;\n }\n const badge = element(\"status\").textContent;\n if (!badge || badge === \"loading\" || badge === \"waiting\") {\n return true;\n }\n return UNBUILT_STATUSES.indexOf(badge) !== -1;\n }\n\n /**\n * Keep URLs in memory for openLink \u2014 never print them (preview JWTs are\n * huge and ugly in the card).\n */\n function renderActions() {\n element(\"openEditor\").disabled = !editUrl || !canOpenLinks;\n element(\"openPreview\").disabled = !previewUrl || !canOpenLinks;\n // Once the app is live, publishing again is not what anyone wants from\n // this button \u2014 going to the live app is.\n element(\"publishApp\").textContent = publishUrl\n ? \"Open published app\"\n : \"Publish app\";\n element(\"publishApp\").disabled = publishUrl\n ? !canOpenLinks\n : !applicationId ||\n !canCallTools ||\n publishing ||\n nothingToPublish();\n // Only warn about what is actually broken. Hosts that do open links\n // handle local http fine; if one refuses, refused() says so then.\n if (!canOpenLinks && (editUrl || previewUrl) && !publishUrl) {\n note(\"This host cannot open links for me \u2014 ask the model for an https preview URL.\");\n }\n reportSize();\n }\n\n /** Only ever ask the host to open a real web address. */\n function webUrl(candidate) {\n try {\n const parsed = new URL(candidate);\n return parsed.protocol === \"http:\" || parsed.protocol === \"https:\"\n ? candidate\n : \"\";\n } catch {\n return \"\";\n }\n }\n\n /**\n * Merges whatever the host sent. Hosts replay tool input as well as tool\n * results, and the input carries no status or URLs \u2014 overwriting from a\n * partial payload is what showed the card as \"unknown\".\n *\n * Hosts also disagree on the shape: some pass the capability JSON, some\n * pass the MCP content/text envelope (Claude Desktop on initialize), and\n * some nest that under structuredContent.\n */\n function applyPayload(raw) {\n let data = raw;\n if (typeof raw === \"string\") {\n try {\n data = JSON.parse(raw);\n } catch {\n return;\n }\n }\n if (!data || typeof data !== \"object\") {\n return;\n }\n // MCP tool-result / initialize toolResult envelope.\n if (Array.isArray(data.content)) {\n applyContent(data.content);\n if (data.structuredContent) {\n applyPayload(data.structuredContent);\n }\n return;\n }\n if (data.result && typeof data.result === \"object\") {\n applyPayload(data.result);\n return;\n }\n const value = data.kind === \"ok\" ? data.value : data;\n if (!value || typeof value !== \"object\") {\n return;\n }\n if (typeof value.status === \"string\") {\n element(\"status\").textContent = value.status;\n }\n if (typeof value.applicationId === \"string\") {\n applicationId = value.applicationId;\n renderIdentity();\n }\n if (typeof value.name === \"string\" && value.name) {\n appName = value.name;\n renderIdentity();\n }\n if (typeof value.commitId === \"string\") {\n commitId = value.commitId;\n }\n if (typeof value.pendingAction === \"string\") {\n pendingAction = value.pendingAction;\n } else if (typeof value.status === \"string\") {\n pendingAction = \"\";\n }\n if (typeof value.screenshotBase64 === \"string\") {\n showScreenshot(value.screenshotBase64, \"image/jpeg\");\n }\n if (typeof value.editUrl === \"string\") {\n editUrl = webUrl(value.editUrl);\n }\n if (typeof value.previewUrl === \"string\") {\n previewUrl = webUrl(value.previewUrl);\n }\n if (typeof value.publishUrl === \"string\") {\n publishUrl = webUrl(value.publishUrl);\n }\n if (typeof value.nextPollAfterMs === \"number\") {\n pollAfterMs = value.nextPollAfterMs;\n }\n // Hosts that deliver URLs without a status left the badge on the HTML\n // default (\"loading\") even after the app was built.\n const badge = element(\"status\").textContent;\n if (\n !value.status &&\n editUrl &&\n (badge === \"\" || badge === \"loading\" || badge === \"waiting\")\n ) {\n element(\"status\").textContent = previewUrl ? \"ready\" : \"building\";\n }\n renderActions();\n }\n\n /**\n * Re-ask get_app when the host gave us no result, or while status is\n * still building. wait:false and ensurePreview:false so polls only\n * ask for status. Honor nextPollAfterMs; 0 means stop.\n */\n function clearRefreshTimer() {\n if (refreshTimer) {\n clearTimeout(refreshTimer);\n refreshTimer = 0;\n }\n }\n\n function retryDelay() {\n return Math.max(MIN_POLL_MS, pollAfterMs || MIN_POLL_MS);\n }\n\n function scheduleRefresh(delayMs) {\n clearRefreshTimer();\n if (refreshAttempts >= MAX_REFRESH_ATTEMPTS) {\n note(\"Stopped checking whether the app is still building.\");\n return;\n }\n refreshTimer = setTimeout(() => {\n refreshTimer = 0;\n refreshFromServer();\n }, delayMs);\n }\n\n function refreshFromServer() {\n clearRefreshTimer();\n if (!canCallTools || !applicationId || refreshInFlight) {\n return;\n }\n if (typeof document.hidden === \"boolean\" && document.hidden) {\n scheduleRefresh(retryDelay());\n return;\n }\n const badge = element(\"status\").textContent;\n if (editUrl && badge !== \"building\") {\n return;\n }\n if (refreshAttempts >= MAX_REFRESH_ATTEMPTS) {\n note(\"Stopped checking whether the app is still building.\");\n return;\n }\n refreshAttempts += 1;\n const generation = refreshGeneration;\n refreshInFlight = true;\n request(\"tools/call\", {\n name: \"get_app\",\n arguments: {\n applicationId,\n ensurePreview: false,\n wait: false,\n },\n })\n .then((result) => {\n refreshInFlight = false;\n if (generation !== refreshGeneration) {\n if (element(\"status\").textContent === \"building\") {\n scheduleRefresh(retryDelay());\n }\n return;\n }\n if (!result || result.isError) {\n scheduleRefresh(retryDelay());\n return;\n }\n applyPayload(result);\n if (result.structuredContent) {\n applyPayload(result.structuredContent);\n }\n if (element(\"status\").textContent !== \"building\") {\n return;\n }\n if (pollAfterMs === 0) {\n return;\n }\n scheduleRefresh(retryDelay());\n })\n .catch(() => {\n refreshInFlight = false;\n if (generation !== refreshGeneration) {\n return;\n }\n scheduleRefresh(retryDelay());\n });\n }\n\n function applyHostContext(context) {\n if (!context || typeof context !== \"object\") {\n return;\n }\n const variables = context.styles && context.styles.variables;\n const style = document.documentElement.style;\n if (variables && style && typeof style.setProperty === \"function\") {\n for (const name of Object.keys(variables)) {\n const value = variables[name];\n if (typeof value === \"string\") {\n style.setProperty(name, value);\n }\n }\n }\n reportSize();\n }\n\n function refused(url) {\n note(\n isPlainHttp(url)\n ? \"This host only opens https links, and this app is served over http \u2014 ask for an https preview URL.\"\n : \"The host could not open the link \u2014 try again or ask the model for another URL.\",\n );\n }\n\n function openLink(url) {\n if (!url || !canOpenLinks) {\n return;\n }\n request(\"ui/open-link\", { url })\n .then((result) => {\n if (result && result.isError) {\n refused(url);\n return;\n }\n note(\"\");\n })\n .catch(() => refused(url));\n }\n\n /**\n * Asks the host to proxy publish_app back to this MCP server. The prompt\n * is the commit message createCommit needs; the card supplies a fixed one\n * so the user does not have to type through the model.\n */\n function publish() {\n if (!applicationId || !canCallTools || publishing) {\n return;\n }\n if (nothingToPublish()) {\n note(\"Nothing to publish yet: this turn did not build the app.\");\n return;\n }\n publishing = true;\n renderActions();\n note(\"Publishing\u2026\");\n const args = {\n applicationId,\n idempotencyKey:\n \"mcp-app-publish:\" + applicationId + \":\" + Date.now(),\n prompt: \"Published from Gateway status card\",\n };\n if (commitId) {\n args.commitId = commitId;\n }\n request(\"tools/call\", { name: \"publish_app\", arguments: args })\n .then((result) => {\n publishing = false;\n if (!result || result.isError) {\n const text =\n result &&\n Array.isArray(result.content) &&\n result.content[0] &&\n result.content[0].text\n ? String(result.content[0].text)\n : \"Publish failed.\";\n note(text.slice(0, 280));\n renderActions();\n return;\n }\n applyContent(result.content || []);\n if (result.structuredContent) {\n applyPayload(result.structuredContent);\n }\n note(\n publishUrl\n ? \"Published \u2014 open the live app with Open published app.\"\n : \"Published \u2014 the app is live.\",\n );\n renderActions();\n })\n .catch((error) => {\n publishing = false;\n note(\n (error && error.message) ||\n \"The host could not call publish_app.\",\n );\n renderActions();\n });\n }\n\n function handleHostMessage(event) {\n // App documents are opaque-origin, so the host window is the only\n // identity available to authenticate a message against.\n if (event.source !== window.parent) {\n return;\n }\n const data = event.data;\n if (!data || typeof data !== \"object\") {\n return;\n }\n if (data.method === \"ping\") {\n post({ jsonrpc: \"2.0\", id: data.id, result: {} });\n return;\n }\n if (data.id != null && pending.has(data.id)) {\n const waiter = pending.get(data.id);\n pending.delete(data.id);\n if (data.error) {\n waiter.reject(data.error);\n } else {\n waiter.resolve(data.result);\n }\n return;\n }\n const method = data.method;\n const params = data.params || {};\n if (\n method === \"ui/notifications/tool-result\" ||\n method === \"ui/tool-result\" ||\n method === \"tools/call\"\n ) {\n applyContent(params.content || params.result?.content || []);\n if (params.structuredContent) {\n applyPayload(params.structuredContent);\n }\n refreshGeneration += 1;\n if (element(\"status\").textContent === \"building\") {\n refreshFromServer();\n }\n }\n if (method === \"ui/notifications/tool-input\" && params.arguments) {\n applyPayload(params.arguments);\n refreshFromServer();\n }\n if (method === \"ui/notifications/host-context-changed\") {\n applyHostContext(params);\n }\n }\n\n window.addEventListener(\"message\", handleHostMessage);\n\n element(\"openEditor\").addEventListener(\"click\", () => openLink(editUrl));\n element(\"openPreview\").addEventListener(\"click\", () =>\n openLink(previewUrl),\n );\n element(\"publishApp\").addEventListener(\"click\", () => {\n if (publishUrl) {\n openLink(publishUrl);\n return;\n }\n publish();\n });\n\n if (typeof ResizeObserver === \"function\") {\n new ResizeObserver(reportSize).observe(document.documentElement);\n }\n\n void request(\"ui/initialize\", {\n appCapabilities: {\n availableDisplayModes: [\"inline\"],\n },\n appInfo: { name: \"gateway-app-status\", version: \"0.0.6\" },\n protocolVersion: PROTOCOL_VERSION,\n })\n .then((result) => {\n // Hosts hold back tool results until the app confirms it is ready.\n notify(\"ui/notifications/initialized\", {});\n // Buttons that cannot work are worse than no buttons: hosts without\n // openLinks silently drop ui/open-link.\n canOpenLinks = Boolean(\n result && result.hostCapabilities && result.hostCapabilities.openLinks,\n );\n canCallTools = Boolean(\n result &&\n result.hostCapabilities &&\n result.hostCapabilities.serverTools,\n );\n applyHostContext(result && result.hostContext);\n renderActions();\n if (result && result.toolResult) {\n applyPayload(result.toolResult);\n }\n refreshFromServer();\n })\n .catch(() => {\n // Hosts that push tool results via notification still work.\n })\n .finally(reportSize);\n })();\n </script>\n</body>\n</html>\n";