@superblocksteam/gateway 2.0.0-SNAPSHOT.1d4c72c0ab174c21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +87 -0
- package/README.md +291 -0
- package/dist/agents/resolve-orchestrator-url.d.ts +22 -0
- package/dist/agents/resolve-orchestrator-url.js +38 -0
- package/dist/agents/resolve-orchestrator-url.js.map +1 -0
- package/dist/capabilities/integration-metadata.d.ts +28 -0
- package/dist/capabilities/integration-metadata.js +174 -0
- package/dist/capabilities/integration-metadata.js.map +1 -0
- package/dist/capabilities/lifecycle.d.ts +93 -0
- package/dist/capabilities/lifecycle.js +3450 -0
- package/dist/capabilities/lifecycle.js.map +1 -0
- package/dist/capabilities/query-integration.d.ts +14 -0
- package/dist/capabilities/query-integration.js +172 -0
- package/dist/capabilities/query-integration.js.map +1 -0
- package/dist/capabilities/source-files-archive.d.ts +11 -0
- package/dist/capabilities/source-files-archive.js +54 -0
- package/dist/capabilities/source-files-archive.js.map +1 -0
- package/dist/capabilities/types.d.ts +542 -0
- package/dist/capabilities/types.js +86 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/capture/browser-contract.d.ts +46 -0
- package/dist/capture/browser-contract.js +34 -0
- package/dist/capture/browser-contract.js.map +1 -0
- package/dist/capture/browser-instructions.d.ts +10 -0
- package/dist/capture/browser-instructions.js +18 -0
- package/dist/capture/browser-instructions.js.map +1 -0
- package/dist/capture/capture-library-probe.d.ts +55 -0
- package/dist/capture/capture-library-probe.js +177 -0
- package/dist/capture/capture-library-probe.js.map +1 -0
- package/dist/capture/capture-library.d.ts +52 -0
- package/dist/capture/capture-library.js +249 -0
- package/dist/capture/capture-library.js.map +1 -0
- package/dist/capture/classify-library-paint.d.ts +21 -0
- package/dist/capture/classify-library-paint.js +13 -0
- package/dist/capture/classify-library-paint.js.map +1 -0
- package/dist/capture/host-mcp-scan.d.ts +16 -0
- package/dist/capture/host-mcp-scan.js +64 -0
- package/dist/capture/host-mcp-scan.js.map +1 -0
- package/dist/capture/library-parent-script.d.ts +35 -0
- package/dist/capture/library-parent-script.js +82 -0
- package/dist/capture/library-parent-script.js.map +1 -0
- package/dist/capture/mode.d.ts +29 -0
- package/dist/capture/mode.js +65 -0
- package/dist/capture/mode.js.map +1 -0
- package/dist/config.d.ts +148 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +9 -0
- package/dist/debug.js.map +1 -0
- package/dist/deps.d.ts +38 -0
- package/dist/deps.js +2 -0
- package/dist/deps.js.map +1 -0
- package/dist/health/readiness.d.ts +99 -0
- package/dist/health/readiness.js +202 -0
- package/dist/health/readiness.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/filters.d.ts +8 -0
- package/dist/integrations/filters.js +40 -0
- package/dist/integrations/filters.js.map +1 -0
- package/dist/integrations/map.d.ts +27 -0
- package/dist/integrations/map.js +43 -0
- package/dist/integrations/map.js.map +1 -0
- package/dist/integrations/profile-key.d.ts +19 -0
- package/dist/integrations/profile-key.js +35 -0
- package/dist/integrations/profile-key.js.map +1 -0
- package/dist/integrations/read-only-postgres-query.d.ts +2 -0
- package/dist/integrations/read-only-postgres-query.js +164 -0
- package/dist/integrations/read-only-postgres-query.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -0
- package/dist/orchestrator/client.d.ts +62 -0
- package/dist/orchestrator/client.js +160 -0
- package/dist/orchestrator/client.js.map +1 -0
- package/dist/playwright/ensure-chromium.d.ts +24 -0
- package/dist/playwright/ensure-chromium.js +60 -0
- package/dist/playwright/ensure-chromium.js.map +1 -0
- package/dist/preview/capture-screenshot.d.ts +67 -0
- package/dist/preview/capture-screenshot.js +179 -0
- package/dist/preview/capture-screenshot.js.map +1 -0
- package/dist/preview/viewer-url.d.ts +82 -0
- package/dist/preview/viewer-url.js +130 -0
- package/dist/preview/viewer-url.js.map +1 -0
- package/dist/process/fault-barrier.d.ts +55 -0
- package/dist/process/fault-barrier.js +113 -0
- package/dist/process/fault-barrier.js.map +1 -0
- package/dist/sabs/agent-facing-text.d.ts +35 -0
- package/dist/sabs/agent-facing-text.js +165 -0
- package/dist/sabs/agent-facing-text.js.map +1 -0
- package/dist/sabs/app-state.d.ts +126 -0
- package/dist/sabs/app-state.js +332 -0
- package/dist/sabs/app-state.js.map +1 -0
- package/dist/sabs/awaited-decision.d.ts +47 -0
- package/dist/sabs/awaited-decision.js +124 -0
- package/dist/sabs/awaited-decision.js.map +1 -0
- package/dist/sabs/browser-context.d.ts +53 -0
- package/dist/sabs/browser-context.js +92 -0
- package/dist/sabs/browser-context.js.map +1 -0
- package/dist/sabs/editor-client-methods.d.ts +164 -0
- package/dist/sabs/editor-client-methods.js +750 -0
- package/dist/sabs/editor-client-methods.js.map +1 -0
- package/dist/sabs/editor-socket.d.ts +84 -0
- package/dist/sabs/editor-socket.js +64 -0
- package/dist/sabs/editor-socket.js.map +1 -0
- package/dist/sabs/recent-tool-runs.d.ts +14 -0
- package/dist/sabs/recent-tool-runs.js +61 -0
- package/dist/sabs/recent-tool-runs.js.map +1 -0
- package/dist/sabs/session-peer.d.ts +392 -0
- package/dist/sabs/session-peer.js +11 -0
- package/dist/sabs/session-peer.js.map +1 -0
- package/dist/sabs/streamed-reply.d.ts +42 -0
- package/dist/sabs/streamed-reply.js +110 -0
- package/dist/sabs/streamed-reply.js.map +1 -0
- package/dist/sabs/turn-collector.d.ts +169 -0
- package/dist/sabs/turn-collector.js +506 -0
- package/dist/sabs/turn-collector.js.map +1 -0
- package/dist/sabs/websocket-session-peer.d.ts +540 -0
- package/dist/sabs/websocket-session-peer.js +3289 -0
- package/dist/sabs/websocket-session-peer.js.map +1 -0
- package/dist/security/constant-time.d.ts +9 -0
- package/dist/security/constant-time.js +13 -0
- package/dist/security/constant-time.js.map +1 -0
- package/dist/server/client.d.ts +405 -0
- package/dist/server/client.js +684 -0
- package/dist/server/client.js.map +1 -0
- package/dist/server/identity-reads.d.ts +76 -0
- package/dist/server/identity-reads.js +209 -0
- package/dist/server/identity-reads.js.map +1 -0
- package/dist/start.d.ts +24 -0
- package/dist/start.js +81 -0
- package/dist/start.js.map +1 -0
- package/dist/stores/memory.d.ts +42 -0
- package/dist/stores/memory.js +121 -0
- package/dist/stores/memory.js.map +1 -0
- package/dist/stores/types.d.ts +74 -0
- package/dist/stores/types.js +11 -0
- package/dist/stores/types.js.map +1 -0
- package/dist/telemetry/mcp-client.d.ts +22 -0
- package/dist/telemetry/mcp-client.js +140 -0
- package/dist/telemetry/mcp-client.js.map +1 -0
- package/dist/telemetry/metrics.d.ts +41 -0
- package/dist/telemetry/metrics.js +103 -0
- package/dist/telemetry/metrics.js.map +1 -0
- package/dist/telemetry/runtime.d.ts +9 -0
- package/dist/telemetry/runtime.js +118 -0
- package/dist/telemetry/runtime.js.map +1 -0
- package/dist/transports/mcp/admin-tools.d.ts +56 -0
- package/dist/transports/mcp/admin-tools.js +252 -0
- package/dist/transports/mcp/admin-tools.js.map +1 -0
- package/dist/transports/mcp/app-status-html.d.ts +11 -0
- package/dist/transports/mcp/app-status-html.js +899 -0
- package/dist/transports/mcp/app-status-html.js.map +1 -0
- package/dist/transports/mcp/client-presentation.d.ts +16 -0
- package/dist/transports/mcp/client-presentation.js +13 -0
- package/dist/transports/mcp/client-presentation.js.map +1 -0
- package/dist/transports/mcp/cowork-editor-url.d.ts +6 -0
- package/dist/transports/mcp/cowork-editor-url.js +10 -0
- package/dist/transports/mcp/cowork-editor-url.js.map +1 -0
- package/dist/transports/mcp/decision-card-html.d.ts +26 -0
- package/dist/transports/mcp/decision-card-html.js +876 -0
- package/dist/transports/mcp/decision-card-html.js.map +1 -0
- package/dist/transports/mcp/decision-elicitation.d.ts +116 -0
- package/dist/transports/mcp/decision-elicitation.js +292 -0
- package/dist/transports/mcp/decision-elicitation.js.map +1 -0
- package/dist/transports/mcp/dispatch-probe.d.ts +24 -0
- package/dist/transports/mcp/dispatch-probe.js +48 -0
- package/dist/transports/mcp/dispatch-probe.js.map +1 -0
- package/dist/transports/mcp/editor-document-probe.d.ts +4 -0
- package/dist/transports/mcp/editor-document-probe.js +35 -0
- package/dist/transports/mcp/editor-document-probe.js.map +1 -0
- package/dist/transports/mcp/editor-integration-setup-url.d.ts +8 -0
- package/dist/transports/mcp/editor-integration-setup-url.js +23 -0
- package/dist/transports/mcp/editor-integration-setup-url.js.map +1 -0
- package/dist/transports/mcp/format-tool-content.d.ts +20 -0
- package/dist/transports/mcp/format-tool-content.js +89 -0
- package/dist/transports/mcp/format-tool-content.js.map +1 -0
- package/dist/transports/mcp/instructions/index.d.ts +23 -0
- package/dist/transports/mcp/instructions/index.js +81 -0
- package/dist/transports/mcp/instructions/index.js.map +1 -0
- package/dist/transports/mcp/instructions/result.d.ts +18 -0
- package/dist/transports/mcp/instructions/result.js +58 -0
- package/dist/transports/mcp/instructions/result.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/ask-user.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/ask-user.js +17 -0
- package/dist/transports/mcp/instructions/tools/ask-user.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/check-app-progress.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/check-app-progress.js +75 -0
- package/dist/transports/mcp/instructions/tools/check-app-progress.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/check-publish-progress.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/check-publish-progress.js +23 -0
- package/dist/transports/mcp/instructions/tools/check-publish-progress.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/copy.d.ts +14 -0
- package/dist/transports/mcp/instructions/tools/copy.js +35 -0
- package/dist/transports/mcp/instructions/tools/copy.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/create-integration.d.ts +4 -0
- package/dist/transports/mcp/instructions/tools/create-integration.js +41 -0
- package/dist/transports/mcp/instructions/tools/create-integration.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/edit-app.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/edit-app.js +18 -0
- package/dist/transports/mcp/instructions/tools/edit-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/get-app.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/get-app.js +47 -0
- package/dist/transports/mcp/instructions/tools/get-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/get-integration-metadata.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/get-integration-metadata.js +13 -0
- package/dist/transports/mcp/instructions/tools/get-integration-metadata.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/index.d.ts +7 -0
- package/dist/transports/mcp/instructions/tools/index.js +26 -0
- package/dist/transports/mcp/instructions/tools/index.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/preview-app.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/preview-app.js +14 -0
- package/dist/transports/mcp/instructions/tools/preview-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/publish-app.d.ts +3 -0
- package/dist/transports/mcp/instructions/tools/publish-app.js +23 -0
- package/dist/transports/mcp/instructions/tools/publish-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/start-app.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/start-app.js +22 -0
- package/dist/transports/mcp/instructions/tools/start-app.js.map +1 -0
- package/dist/transports/mcp/instructions/tools/upload-artifact.d.ts +2 -0
- package/dist/transports/mcp/instructions/tools/upload-artifact.js +13 -0
- package/dist/transports/mcp/instructions/tools/upload-artifact.js.map +1 -0
- package/dist/transports/mcp/mcp-app-brand-css.d.ts +1 -0
- package/dist/transports/mcp/mcp-app-brand-css.js +180 -0
- package/dist/transports/mcp/mcp-app-brand-css.js.map +1 -0
- package/dist/transports/mcp/mount.d.ts +22 -0
- package/dist/transports/mcp/mount.js +1040 -0
- package/dist/transports/mcp/mount.js.map +1 -0
- package/dist/transports/mcp/native-browser-presence.d.ts +45 -0
- package/dist/transports/mcp/native-browser-presence.js +158 -0
- package/dist/transports/mcp/native-browser-presence.js.map +1 -0
- package/dist/transports/mcp/plan-approval.d.ts +38 -0
- package/dist/transports/mcp/plan-approval.js +175 -0
- package/dist/transports/mcp/plan-approval.js.map +1 -0
- package/dist/transports/mcp/progress-notifier.d.ts +39 -0
- package/dist/transports/mcp/progress-notifier.js +52 -0
- package/dist/transports/mcp/progress-notifier.js.map +1 -0
- package/dist/transports/mcp/session-directory.d.ts +7 -0
- package/dist/transports/mcp/session-directory.js +18 -0
- package/dist/transports/mcp/session-directory.js.map +1 -0
- package/dist/transports/mcp/tool-names.d.ts +2 -0
- package/dist/transports/mcp/tool-names.js +2 -0
- package/dist/transports/mcp/tool-names.js.map +1 -0
- package/package.json +78 -0
- package/skills/superblocks-build/SKILL.md +59 -0
- package/skills/superblocks-import/SKILL.md +88 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { buildToolRegistry, executeToolCall, runWithAuthContext, toolDefinitions, } from "@superblocksteam/mcp-server";
|
|
3
|
+
import { gatewayDebug, gatewayDebugStack } from "../../debug.js";
|
|
4
|
+
import { attachAdminAgentInstructions } from "./instructions/index.js";
|
|
5
|
+
import { isRecord } from "./instructions/result.js";
|
|
6
|
+
import { isPublicIntegration } from "./instructions/tools/create-integration.js";
|
|
7
|
+
/**
|
|
8
|
+
* Loose JSON-Schema -> Zod conversion so `registerTool` can list Admin tools
|
|
9
|
+
* with usable shapes. Handlers still validate through `@superblocksteam/mcp-server`.
|
|
10
|
+
*/
|
|
11
|
+
export function jsonSchemaToZodShape(inputSchema, options = {}) {
|
|
12
|
+
const properties = inputSchema?.properties ?? {};
|
|
13
|
+
const required = new Set(inputSchema?.required ?? []);
|
|
14
|
+
for (const key of options.optionalKeys ?? []) {
|
|
15
|
+
required.delete(key);
|
|
16
|
+
}
|
|
17
|
+
const shape = {};
|
|
18
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
19
|
+
let field = jsonSchemaPropertyToZod(prop ?? {});
|
|
20
|
+
if (!required.has(key)) {
|
|
21
|
+
field = field.optional();
|
|
22
|
+
}
|
|
23
|
+
shape[key] = field;
|
|
24
|
+
}
|
|
25
|
+
return shape;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Arguments the gateway fills in itself, so the model never has to go find
|
|
29
|
+
* them. A required `base_url` reads as missing information: rather than call
|
|
30
|
+
* the tool it was asked for, a client goes hunting for the environment first.
|
|
31
|
+
*/
|
|
32
|
+
const GATEWAY_SUPPLIED_ARGUMENTS = {
|
|
33
|
+
base_url: "Omit this. The gateway always sends its own Superblocks Server URL; any value here is replaced.",
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Admin tools the gateway keeps to itself.
|
|
37
|
+
*
|
|
38
|
+
* `get_auth_status` answers questions already settled before the model sees a
|
|
39
|
+
* tool (the CLI session already authenticated; the gateway injects its Server URL).
|
|
40
|
+
*
|
|
41
|
+
* `checkout_application` writes caller-controlled paths on the gateway host
|
|
42
|
+
* filesystem. Keep that off stdio MCP until a sandboxed destination model lands;
|
|
43
|
+
* use the CLI/workspace checkout path instead.
|
|
44
|
+
*/
|
|
45
|
+
const OMITTED_ADMIN_TOOLS = new Set([
|
|
46
|
+
"checkout_application",
|
|
47
|
+
"get_auth_status",
|
|
48
|
+
]);
|
|
49
|
+
function gatewayAdminInputShape(inputSchema) {
|
|
50
|
+
const shape = jsonSchemaToZodShape(inputSchema, {
|
|
51
|
+
optionalKeys: Object.keys(GATEWAY_SUPPLIED_ARGUMENTS),
|
|
52
|
+
});
|
|
53
|
+
for (const [key, description] of Object.entries(GATEWAY_SUPPLIED_ARGUMENTS)) {
|
|
54
|
+
const field = shape[key];
|
|
55
|
+
if (field) {
|
|
56
|
+
shape[key] = field.describe(description);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return shape;
|
|
60
|
+
}
|
|
61
|
+
function jsonSchemaPropertyToZod(prop) {
|
|
62
|
+
if (prop.enum && prop.enum.length > 0) {
|
|
63
|
+
const values = prop.enum.filter((v) => typeof v === "string");
|
|
64
|
+
if (values.length === prop.enum.length && values.length > 0) {
|
|
65
|
+
return z.enum(values);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const rawType = Array.isArray(prop.type) ? prop.type[0] : prop.type;
|
|
69
|
+
switch (rawType) {
|
|
70
|
+
case "string":
|
|
71
|
+
return z.string();
|
|
72
|
+
case "number":
|
|
73
|
+
case "integer":
|
|
74
|
+
return z.number();
|
|
75
|
+
case "boolean":
|
|
76
|
+
return z.boolean();
|
|
77
|
+
case "array":
|
|
78
|
+
return z.array(prop.items ? jsonSchemaPropertyToZod(prop.items) : z.unknown());
|
|
79
|
+
case "object":
|
|
80
|
+
if (prop.properties) {
|
|
81
|
+
return z
|
|
82
|
+
.object(jsonSchemaToZodShape({
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: prop.properties,
|
|
85
|
+
required: prop.required,
|
|
86
|
+
}))
|
|
87
|
+
.passthrough();
|
|
88
|
+
}
|
|
89
|
+
return z.record(z.string(), z.unknown());
|
|
90
|
+
default:
|
|
91
|
+
return z.unknown();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function resolveToken(options, auth) {
|
|
95
|
+
if (options.resolveApiKey) {
|
|
96
|
+
return options.resolveApiKey(auth);
|
|
97
|
+
}
|
|
98
|
+
if (options.apiKey) {
|
|
99
|
+
return Promise.resolve(options.apiKey);
|
|
100
|
+
}
|
|
101
|
+
return Promise.reject(new Error("Admin tools require apiKey or resolveApiKey"));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gateway product copy names the builder Superblocks. Admin tool definitions
|
|
105
|
+
* still mention the retired "Clark" alias in places; rewrite for this surface
|
|
106
|
+
* so clients do not reintroduce that name.
|
|
107
|
+
*/
|
|
108
|
+
export function superblocksProductCopy(text) {
|
|
109
|
+
return text
|
|
110
|
+
.replaceAll(/\bClark AI Apps\b/g, "Superblocks AI Apps")
|
|
111
|
+
.replaceAll(/\bClark\b/g, "Superblocks");
|
|
112
|
+
}
|
|
113
|
+
/** Completes MCP hints without overriding shared Admin definitions. */
|
|
114
|
+
export function completeToolAnnotations(annotations) {
|
|
115
|
+
const readOnlyHint = annotations?.readOnlyHint ?? false;
|
|
116
|
+
return {
|
|
117
|
+
...annotations,
|
|
118
|
+
destructiveHint: annotations?.destructiveHint ?? (readOnlyHint ? false : true),
|
|
119
|
+
idempotentHint: annotations?.idempotentHint ?? readOnlyHint,
|
|
120
|
+
openWorldHint: annotations?.openWorldHint ?? true,
|
|
121
|
+
readOnlyHint,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function parseCreateIntegrationPayload(result) {
|
|
125
|
+
if (result.isError || result.content[0]?.type !== "text") {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
let value;
|
|
129
|
+
try {
|
|
130
|
+
value = JSON.parse(result.content[0].text);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
return isRecord(value) ? value : undefined;
|
|
136
|
+
}
|
|
137
|
+
function withCreateIntegrationPayload(result, value) {
|
|
138
|
+
return {
|
|
139
|
+
...result,
|
|
140
|
+
content: [{ type: "text", text: JSON.stringify(value) }],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async function withEditorIntegrationSetupUrl(result, resolveUrl) {
|
|
144
|
+
const value = parseCreateIntegrationPayload(result);
|
|
145
|
+
if (!value ||
|
|
146
|
+
isPublicIntegration(value) ||
|
|
147
|
+
(isRecord(value.integration) && value.integration.kind === "SECRET") ||
|
|
148
|
+
typeof value.integration_id !== "string" ||
|
|
149
|
+
!value.integration_id ||
|
|
150
|
+
!resolveUrl) {
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
let editorUrl;
|
|
154
|
+
try {
|
|
155
|
+
editorUrl = await resolveUrl(value.integration_id);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
gatewayDebug("create_integration editor URL enrichment failed", {
|
|
159
|
+
integrationId: value.integration_id,
|
|
160
|
+
message: error instanceof Error ? error.message : String(error),
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
if (!editorUrl) {
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
return withCreateIntegrationPayload(result, {
|
|
168
|
+
...value,
|
|
169
|
+
integration_url: editorUrl,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function withCreateIntegrationBrowserNavigation(result) {
|
|
173
|
+
const value = parseCreateIntegrationPayload(result);
|
|
174
|
+
if (!value || typeof value.integration_url !== "string") {
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
...result,
|
|
179
|
+
structuredContent: {
|
|
180
|
+
...value,
|
|
181
|
+
browserNavigation: {
|
|
182
|
+
action: "open_editor",
|
|
183
|
+
url: value.integration_url,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Registers customer-profile Admin MCP tools on the same McpServer as Builder
|
|
190
|
+
* tools. Each call runs under `runWithAuthContext` with the Gateway's
|
|
191
|
+
* downstream credential, against the `serverUrl` that credential belongs to.
|
|
192
|
+
*/
|
|
193
|
+
export function registerAdminTools(server, options) {
|
|
194
|
+
const registry = buildToolRegistry(toolDefinitions, "customer", {
|
|
195
|
+
requireEntitledPlan: options.localAgentMode !== true,
|
|
196
|
+
});
|
|
197
|
+
for (const tool of registry.listTools()) {
|
|
198
|
+
if (OMITTED_ADMIN_TOOLS.has(tool.name)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const definition = toolDefinitions.find((d) => d.name === tool.name);
|
|
202
|
+
server.registerTool(tool.name, {
|
|
203
|
+
annotations: completeToolAnnotations(tool.annotations),
|
|
204
|
+
description: superblocksProductCopy(tool.description ?? ""),
|
|
205
|
+
inputSchema: gatewayAdminInputShape(tool.inputSchema),
|
|
206
|
+
title: tool.title ?? definition?.title,
|
|
207
|
+
}, async (args, extra) => {
|
|
208
|
+
gatewayDebugStack("admin tool started", {
|
|
209
|
+
"tool.argument_keys": Object.keys(args).sort(),
|
|
210
|
+
"tool.name": tool.name,
|
|
211
|
+
});
|
|
212
|
+
try {
|
|
213
|
+
const token = await resolveToken(options, extra.authInfo);
|
|
214
|
+
const baseUrl = options.serverUrl.replace(/\/$/, "");
|
|
215
|
+
const callArgs = {
|
|
216
|
+
...args,
|
|
217
|
+
// Overwritten, never merged. The credential this call runs with belongs
|
|
218
|
+
// to the Gateway's own control plane, so a base_url from the model
|
|
219
|
+
// would send that credential to a host the model chose - reachable
|
|
220
|
+
// through any prompt injection that gets as far as a tool call.
|
|
221
|
+
base_url: baseUrl,
|
|
222
|
+
};
|
|
223
|
+
const result = await runWithAuthContext({ baseUrl, token }, () => executeToolCall(tool.name, callArgs, registry));
|
|
224
|
+
gatewayDebug("admin tool finished", {
|
|
225
|
+
"result.kind": "success",
|
|
226
|
+
"tool.name": tool.name,
|
|
227
|
+
});
|
|
228
|
+
if (tool.name !== "create_integration") {
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
const withEditorUrl = await withEditorIntegrationSetupUrl(result, options.resolveEditorIntegrationSetupUrl);
|
|
232
|
+
const profile = options.clientProfile?.();
|
|
233
|
+
const withBrowser = profile?.hasNativeBrowser === true
|
|
234
|
+
? withCreateIntegrationBrowserNavigation(withEditorUrl)
|
|
235
|
+
: withEditorUrl;
|
|
236
|
+
return profile
|
|
237
|
+
? attachAdminAgentInstructions("create_integration", withBrowser, profile)
|
|
238
|
+
: withBrowser;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
gatewayDebug("admin tool finished", {
|
|
242
|
+
"error.type": error instanceof Error ? error.constructor.name : typeof error,
|
|
243
|
+
"result.kind": "error",
|
|
244
|
+
"tool.name": tool.name,
|
|
245
|
+
});
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return registry;
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=admin-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-tools.js","sourceRoot":"","sources":["../../../src/transports/mcp/admin-tools.ts"],"names":[],"mappings":"AAOA,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;AAEjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AAiDjF;;;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;IACvB,CAAC;IACD,MAAM,KAAK,GAA8B,EAAE,CAAC;IAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACrD,IAAI,KAAK,GAAG,uBAAuB,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GA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AoB,EACpB,WAAW,EACX,OAAO,CACR;oBACH,CAAC,CAAC,WAAW,CAAC;YAClB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,YAAY,CAAC,qBAAqB,EAAE;oBAClC,YAAY,EACV,KAAK,YAAY,KAAK,CAAC,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained MCP App HTML for Gateway status and open-link buttons.
|
|
3
|
+
*
|
|
4
|
+
* openLink buttons keep URLs in JS memory only (not printed).
|
|
5
|
+
*
|
|
6
|
+
* Speaks the MCP Apps postMessage dialect without bundling ext-apps into the
|
|
7
|
+
* card (hosts cache UI resources; keep this file small and inline). Bump the
|
|
8
|
+
* resource URI when the HTML changes so Claude Desktop refreshes its cache.
|
|
9
|
+
*/
|
|
10
|
+
export declare const APP_STATUS_RESOURCE_URI = "ui://gateway/app-status-v35.html";
|
|
11
|
+
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 .head {\n display: flex;\n min-width: 0;\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: var(--border-width-regular, 1px) solid var(--sb-app-border);\n border-radius: var(--border-radius-full, 999px);\n background: var(--sb-app-background-subtle);\n color: var(--sb-app-text-secondary);\n font-size: var(--font-text-xs-size, 12px);\n text-transform: lowercase;\n }\n .status[data-tone=\"info\"] {\n border-color: var(--sb-app-info-border);\n background: var(--sb-app-info-background);\n color: var(--sb-app-info-text);\n }\n .status[data-tone=\"success\"] {\n border-color: var(--sb-app-success-border);\n background: var(--sb-app-success-background);\n color: var(--sb-app-success-text);\n }\n .status[data-tone=\"warning\"] {\n border-color: var(--sb-app-warning-border);\n background: var(--sb-app-warning-background);\n color: var(--sb-app-warning-text);\n }\n .status[data-tone=\"danger\"] {\n border-color: var(--sb-app-danger-border);\n background: var(--sb-app-danger-background);\n color: var(--sb-app-danger-text);\n }\n .meta {\n color: var(--sb-app-text-tertiary);\n font-size: var(--font-text-xs-size, 12px);\n }\n .note {\n color: var(--sb-app-warning-text);\n font-size: var(--font-text-xs-size, 12px);\n }\n .shot {\n display: none;\n max-width: 100%;\n width: 100%;\n border: var(--border-width-regular, 1px) solid var(--sb-app-border);\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 @media (max-width: 360px) {\n .head {\n align-items: flex-start;\n flex-direction: column;\n }\n }\n\n :root {\n color-scheme: light dark;\n --sb-app-background: var(\n --color-background-primary,\n light-dark(#ffffff, #1b1c1f)\n );\n --sb-app-background-subtle: var(\n --color-background-secondary,\n light-dark(#f9fafb, #24272b)\n );\n --sb-app-background-hover: var(\n --color-background-tertiary,\n light-dark(#f3f4f6, #2f3437)\n );\n --sb-app-background-inverse: var(\n --color-background-inverse,\n light-dark(#121517, #f9fafb)\n );\n --sb-app-text: var(\n --color-text-primary,\n light-dark(#121517, #f9fafb)\n );\n --sb-app-text-secondary: var(\n --color-text-secondary,\n light-dark(#5a6272, #c6cad2)\n );\n --sb-app-text-tertiary: var(\n --color-text-tertiary,\n light-dark(#6b7280, #a4aab7)\n );\n --sb-app-text-inverse: var(\n --color-text-inverse,\n light-dark(#ffffff, #121517)\n );\n --sb-app-border: var(\n --color-border-primary,\n light-dark(#e8eaed, #454d5f)\n );\n --sb-app-ring: var(\n --color-ring-primary,\n light-dark(#0077b6, #27bbff)\n );\n --sb-app-info-background: var(\n --color-background-info,\n light-dark(#e6f5ff, #083a50)\n );\n --sb-app-info-text: var(\n --color-text-info,\n light-dark(#00679e, #7dd3fc)\n );\n --sb-app-info-border: var(\n --color-border-info,\n light-dark(#c2e7ff, #075985)\n );\n --sb-app-success-background: var(\n --color-background-success,\n light-dark(#e8f8ef, #0a3926)\n );\n --sb-app-success-text: var(\n --color-text-success,\n light-dark(#087a43, #6ee7b7)\n );\n --sb-app-success-border: var(\n --color-border-success,\n light-dark(#b8e8cf, #087a43)\n );\n --sb-app-warning-background: var(\n --color-background-warning,\n light-dark(#fff7e6, #49350a)\n );\n --sb-app-warning-text: var(\n --color-text-warning,\n light-dark(#946200, #fcd34d)\n );\n --sb-app-warning-border: var(\n --color-border-warning,\n light-dark(#f5d996, #946200)\n );\n --sb-app-danger-background: var(\n --color-background-danger,\n light-dark(#fff1f1, #4a1d1d)\n );\n --sb-app-danger-text: var(\n --color-text-danger,\n light-dark(#c54141, #fca5a5)\n );\n --sb-app-danger-border: var(\n --color-border-danger,\n light-dark(#ffcaca, #c54141)\n );\n }\n * {\n box-sizing: border-box;\n }\n body {\n min-width: 0;\n margin: 0;\n overflow-x: hidden;\n background: transparent;\n color: var(--sb-app-text);\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 }\n .card {\n display: flex;\n min-width: 0;\n flex-direction: column;\n gap: 12px;\n padding: 16px;\n border: var(--border-width-regular, 1px) solid var(--sb-app-border);\n border-radius: var(--border-radius-lg, 12px);\n background: var(--sb-app-background);\n box-shadow: var(--shadow-sm, 0 1px 2px rgba(18, 21, 23, 0.08));\n }\n h1,\n .meta,\n .note {\n min-width: 0;\n overflow-wrap: anywhere;\n }\n .note:empty {\n position: absolute;\n }\n button,\n textarea {\n font: inherit;\n }\n button {\n appearance: none;\n min-width: 0;\n padding: 8px 12px;\n border: var(--border-width-regular, 1px) solid var(--sb-app-border);\n border-radius: var(--border-radius-md, 8px);\n background: var(--sb-app-background-subtle);\n color: var(--sb-app-text);\n font-weight: var(--font-weight-medium, 500);\n line-height: var(--font-text-sm-line-height, 1.45);\n cursor: pointer;\n }\n button:hover:not(:disabled) {\n background: var(--sb-app-background-hover);\n }\n .button-primary {\n border-color: var(--sb-app-background-inverse);\n background: var(--sb-app-background-inverse);\n color: var(--sb-app-text-inverse);\n }\n .button-primary:hover:not(:disabled) {\n border-color: var(--sb-app-background-inverse);\n background: var(--sb-app-background-inverse);\n }\n button:focus-visible,\n textarea:focus-visible,\n a:focus-visible {\n outline: 2px solid var(--sb-app-ring);\n outline-offset: 2px;\n }\n button:disabled {\n opacity: 0.48;\n cursor: not-allowed;\n }\n .actions {\n min-width: 0;\n }\n .actions > button {\n overflow-wrap: anywhere;\n }\n @media (max-width: 360px) {\n .actions {\n flex-direction: column;\n flex-wrap: nowrap;\n }\n .actions > button {\n width: 100%;\n }\n }\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\" data-tone=\"info\" aria-live=\"polite\">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\" aria-live=\"polite\"></div>\n <div class=\"actions\">\n <button id=\"openEditor\" class=\"button-secondary\" type=\"button\" disabled>Open editor</button>\n <button id=\"openPreview\" class=\"button-secondary\" type=\"button\" disabled>Open preview</button>\n <button id=\"publishApp\" class=\"button-primary\" type=\"button\" disabled>Publish app</button>\n </div>\n </div>\n <script>\n (() => {\n const PROTOCOL_VERSION = \"2026-01-26\";\n // Statuses with no usable build to publish. \"building\" is deliberately\n // absent because a stale badge should not strand the button.\n const UNBUILT_STATUSES = [\n \"cancelled\",\n \"checkpoint_failed\",\n \"detached\",\n \"failed\",\n \"live_edit_terminated\",\n \"needs_decision\",\n \"no_changes\",\n \"timeout\",\n ];\n const BLOCKED_ACTIONS = [\n \"answer_question\",\n \"approve_plan\",\n \"open_editor\",\n \"retry_build\",\n ];\n const STATUS_TONES = {\n building: \"info\",\n cancelled: \"warning\",\n checkpoint_failed: \"danger\",\n deployed: \"success\",\n detached: \"warning\",\n failed: \"danger\",\n live_edit_terminated: \"danger\",\n loading: \"info\",\n needs_decision: \"warning\",\n no_changes: \"warning\",\n publish_failed: \"danger\",\n publishing: \"info\",\n ready: \"success\",\n timeout: \"danger\",\n waiting: \"info\",\n };\n let nextId = 1;\n const pending = new Map();\n let applicationId = \"\";\n let appName = \"\";\n let branch = \"\";\n let commitId = \"\";\n let directoryHash = \"\";\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 teardownRequested = false;\n let lastHeight = 0;\n let buildWatchStartedAtMs;\n let refreshInFlightGeneration = -1;\n let refreshTimer = 0;\n let refreshGeneration = 0;\n const BUILD_WATCH_MS = 20 * 60_000;\n const POLL_INTERVAL_MS = 2000;\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 function renderStatus(status) {\n const badge = element(\"status\");\n badge.textContent = status;\n badge.setAttribute(\n \"data-tone\",\n Object.hasOwn(STATUS_TONES, status) ? STATUS_TONES[status] : \"neutral\",\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 if (teardownRequested) {\n return;\n }\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 const badge = element(\"status\").textContent;\n if (UNBUILT_STATUSES.indexOf(badge) !== -1) {\n return true;\n }\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 if (!badge || badge === \"loading\" || badge === \"waiting\") {\n return true;\n }\n return false;\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 const status = element(\"status\").textContent;\n const previewReady = status === \"ready\";\n const rollingOut = status === \"publishing\";\n const published = Boolean(publishUrl) && !rollingOut;\n element(\"openEditor\").disabled = !editUrl || !canOpenLinks;\n element(\"openPreview\").disabled =\n !previewReady || !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 = rollingOut\n ? \"Publishing...\"\n : published\n ? \"Open published app\"\n : \"Publish app\";\n element(\"publishApp\").disabled = rollingOut\n ? true\n : published\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 (\n value.browserNavigation &&\n typeof value.browserNavigation === \"object\" &&\n value.browserNavigation.action === \"open_editor\"\n ) {\n if (!teardownRequested) {\n teardownRequested = true;\n refreshGeneration += 1;\n clearRefreshTimer();\n document.body.hidden = true;\n notify(\"ui/notifications/size-changed\", { height: 0, width: 0 });\n notify(\"ui/notifications/request-teardown\", {});\n }\n return;\n }\n if (teardownRequested) {\n return;\n }\n if (typeof value.status === \"string\") {\n renderStatus(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.branch === \"string\") {\n branch = value.branch;\n }\n if (typeof value.directoryHash === \"string\") {\n directoryHash = value.directoryHash;\n }\n if (\n typeof value.commitId === \"string\" ||\n typeof value.previewUrl === \"string\" ||\n (typeof value.applicationId === \"string\" &&\n typeof value.status === \"string\")\n ) {\n commitId =\n typeof value.commitId === \"string\" ? 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 } else if (typeof value.status === \"string\" && !commitId) {\n 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 renderStatus(previewUrl ? \"ready\" : \"building\");\n }\n renderActions();\n if (\n canCallTools &&\n commitId &&\n element(\"status\").textContent === \"publishing\"\n ) {\n scheduleRefresh(retryDelay());\n }\n }\n\n /**\n * Ask the app-only status tool when the host gave us no result, or while\n * status is still building.\n */\n function clearRefreshTimer() {\n if (refreshTimer) {\n clearTimeout(refreshTimer);\n refreshTimer = 0;\n }\n }\n\n function retryDelay() {\n return POLL_INTERVAL_MS;\n }\n\n function scheduleRefresh(delayMs) {\n clearRefreshTimer();\n if (\n element(\"status\").textContent !== \"publishing\" &&\n buildWatchStartedAtMs !== undefined &&\n Date.now() - buildWatchStartedAtMs >= BUILD_WATCH_MS\n ) {\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 (\n teardownRequested ||\n !canCallTools ||\n refreshInFlightGeneration === refreshGeneration ||\n publishing\n ) {\n return;\n }\n if (typeof document.hidden === \"boolean\" && document.hidden) {\n scheduleRefresh(retryDelay());\n return;\n }\n const badge = element(\"status\").textContent;\n const publishStatus = badge === \"publishing\";\n if (editUrl && badge !== \"building\" && !publishStatus) {\n buildWatchStartedAtMs = undefined;\n return;\n }\n if (!publishStatus) {\n if (badge === \"building\") {\n if (buildWatchStartedAtMs === undefined) {\n buildWatchStartedAtMs = Date.now();\n }\n } else {\n buildWatchStartedAtMs = undefined;\n }\n if (\n buildWatchStartedAtMs !== undefined &&\n Date.now() - buildWatchStartedAtMs >= BUILD_WATCH_MS\n ) {\n note(\"Stopped checking whether the app is still building.\");\n return;\n }\n }\n const generation = refreshGeneration;\n refreshInFlightGeneration = generation;\n const previewStatus = !publishStatus && Boolean(commitId && directoryHash);\n request(\"tools/call\", {\n name: publishStatus\n ? \"check_publish_progress\"\n : previewStatus\n ? \"get_preview_status\"\n : \"get_app_status\",\n arguments: {\n ...(applicationId ? { applicationId } : {}),\n ...(!publishStatus && branch ? { branch } : {}),\n ...(publishStatus && commitId ? { commitId } : {}),\n ...(previewStatus ? { commitId, directoryHash } : {}),\n },\n })\n .then((result) => {\n if (refreshInFlightGeneration === generation) {\n refreshInFlightGeneration = -1;\n }\n if (generation !== refreshGeneration) {\n if (\n !publishing &&\n element(\"status\").textContent === \"building\" &&\n refreshInFlightGeneration !== refreshGeneration\n ) {\n scheduleRefresh(retryDelay());\n }\n return;\n }\n const publishError = publishStatus\n ? terminalPublishErrorOf(result)\n : \"\";\n if (publishError) {\n refreshGeneration += 1;\n clearRefreshTimer();\n publishUrl = \"\";\n renderStatus(\"publish_failed\");\n note(publishError);\n renderActions();\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 const status = element(\"status\").textContent;\n if (status === \"deployed\") {\n note(\n publishUrl\n ? \"Published - open the live app with Open published app.\"\n : \"Published - the app is live.\",\n );\n return;\n }\n if (status === \"publishing\") {\n scheduleRefresh(retryDelay());\n return;\n }\n if (status !== \"building\") {\n return;\n }\n scheduleRefresh(retryDelay());\n })\n .catch(() => {\n if (refreshInFlightGeneration === generation) {\n refreshInFlightGeneration = -1;\n }\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 root = document.documentElement;\n if (context.theme === \"light\" || context.theme === \"dark\") {\n root.setAttribute(\"data-theme\", context.theme);\n root.style.colorScheme = context.theme;\n }\n const variables = context.styles && context.styles.variables;\n const style = root.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 const fonts = context.styles && context.styles.css?.fonts;\n if (typeof fonts === \"string\") {\n let fontStyle = document.getElementById(\"__mcp-host-fonts\");\n if (!fontStyle) {\n fontStyle = document.createElement(\"style\");\n fontStyle.id = \"__mcp-host-fonts\";\n document.head.appendChild(fontStyle);\n }\n fontStyle.textContent = fonts;\n }\n reportSize();\n }\n\n function capabilityFailureOf(result) {\n if (!result || !Array.isArray(result.content)) {\n return null;\n }\n for (const block of result.content) {\n if (!block || block.type !== \"text\" || !block.text) {\n continue;\n }\n try {\n const parsed = JSON.parse(block.text);\n if (parsed && parsed.kind === \"error\") {\n return {\n code: parsed.code || \"\",\n message: parsed.message || parsed.code || \"Tool call failed.\",\n };\n }\n } catch {\n continue;\n }\n }\n return null;\n }\n\n function capabilityErrorOf(result) {\n return capabilityFailureOf(result)?.message || \"\";\n }\n\n function terminalPublishErrorOf(result) {\n const failure = capabilityFailureOf(result);\n if (\n !failure ||\n ![\n \"publish_failed\",\n \"publish_needs_acknowledgement\",\n \"publish_timeout\",\n ].includes(failure.code)\n ) {\n return \"\";\n }\n return failure.message;\n }\n\n /** First text block of a failed tool result, for the note line. */\n function errorTextOf(result, fallback) {\n const capabilityError = capabilityErrorOf(result);\n if (capabilityError) {\n return capabilityError;\n }\n const first =\n result && Array.isArray(result.content) ? result.content[0] : null;\n return first && first.text ? String(first.text).slice(0, 280) : fallback;\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 refreshGeneration += 1;\n clearRefreshTimer();\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 if (branch) {\n args.branch = branch;\n }\n request(\"tools/call\", { name: \"publish_app\", arguments: args })\n .then((result) => {\n publishing = false;\n const publishError = capabilityErrorOf(result);\n if (!result || result.isError || publishError) {\n note(errorTextOf(result, \"Publish failed.\"));\n renderActions();\n refreshFromServer();\n return;\n }\n applyContent(result.content || []);\n if (result.structuredContent) {\n applyPayload(result.structuredContent);\n }\n const status = element(\"status\").textContent;\n note(\n status === \"publishing\"\n ? \"Publish accepted; the deploy is still rolling out.\"\n : publishUrl\n ? \"Published - open the live app with Open published app.\"\n : \"Published - 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 refreshFromServer();\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 (element(\"status\").textContent === \"publishing\") {\n return;\n }\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.8\" },\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 if (result && result.toolResult) {\n applyPayload(result.toolResult);\n }\n if (teardownRequested) {\n return;\n }\n applyHostContext(result && result.hostContext);\n renderActions();\n const badge = element(\"status\").textContent;\n if (badge === \"publishing\") {\n return;\n }\n if (!applicationId && (!badge || badge === \"loading\")) {\n scheduleRefresh(500);\n } else {\n refreshFromServer();\n }\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";
|