@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.
Files changed (248) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +291 -0
  3. package/dist/agents/resolve-orchestrator-url.d.ts +22 -0
  4. package/dist/agents/resolve-orchestrator-url.js +38 -0
  5. package/dist/agents/resolve-orchestrator-url.js.map +1 -0
  6. package/dist/capabilities/integration-metadata.d.ts +28 -0
  7. package/dist/capabilities/integration-metadata.js +174 -0
  8. package/dist/capabilities/integration-metadata.js.map +1 -0
  9. package/dist/capabilities/lifecycle.d.ts +93 -0
  10. package/dist/capabilities/lifecycle.js +3450 -0
  11. package/dist/capabilities/lifecycle.js.map +1 -0
  12. package/dist/capabilities/query-integration.d.ts +14 -0
  13. package/dist/capabilities/query-integration.js +172 -0
  14. package/dist/capabilities/query-integration.js.map +1 -0
  15. package/dist/capabilities/source-files-archive.d.ts +11 -0
  16. package/dist/capabilities/source-files-archive.js +54 -0
  17. package/dist/capabilities/source-files-archive.js.map +1 -0
  18. package/dist/capabilities/types.d.ts +542 -0
  19. package/dist/capabilities/types.js +86 -0
  20. package/dist/capabilities/types.js.map +1 -0
  21. package/dist/capture/browser-contract.d.ts +46 -0
  22. package/dist/capture/browser-contract.js +34 -0
  23. package/dist/capture/browser-contract.js.map +1 -0
  24. package/dist/capture/browser-instructions.d.ts +10 -0
  25. package/dist/capture/browser-instructions.js +18 -0
  26. package/dist/capture/browser-instructions.js.map +1 -0
  27. package/dist/capture/capture-library-probe.d.ts +55 -0
  28. package/dist/capture/capture-library-probe.js +177 -0
  29. package/dist/capture/capture-library-probe.js.map +1 -0
  30. package/dist/capture/capture-library.d.ts +52 -0
  31. package/dist/capture/capture-library.js +249 -0
  32. package/dist/capture/capture-library.js.map +1 -0
  33. package/dist/capture/classify-library-paint.d.ts +21 -0
  34. package/dist/capture/classify-library-paint.js +13 -0
  35. package/dist/capture/classify-library-paint.js.map +1 -0
  36. package/dist/capture/host-mcp-scan.d.ts +16 -0
  37. package/dist/capture/host-mcp-scan.js +64 -0
  38. package/dist/capture/host-mcp-scan.js.map +1 -0
  39. package/dist/capture/library-parent-script.d.ts +35 -0
  40. package/dist/capture/library-parent-script.js +82 -0
  41. package/dist/capture/library-parent-script.js.map +1 -0
  42. package/dist/capture/mode.d.ts +29 -0
  43. package/dist/capture/mode.js +65 -0
  44. package/dist/capture/mode.js.map +1 -0
  45. package/dist/config.d.ts +148 -0
  46. package/dist/config.js +111 -0
  47. package/dist/config.js.map +1 -0
  48. package/dist/debug.d.ts +2 -0
  49. package/dist/debug.js +9 -0
  50. package/dist/debug.js.map +1 -0
  51. package/dist/deps.d.ts +38 -0
  52. package/dist/deps.js +2 -0
  53. package/dist/deps.js.map +1 -0
  54. package/dist/health/readiness.d.ts +99 -0
  55. package/dist/health/readiness.js +202 -0
  56. package/dist/health/readiness.js.map +1 -0
  57. package/dist/index.d.ts +8 -0
  58. package/dist/index.js +8 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/integrations/filters.d.ts +8 -0
  61. package/dist/integrations/filters.js +40 -0
  62. package/dist/integrations/filters.js.map +1 -0
  63. package/dist/integrations/map.d.ts +27 -0
  64. package/dist/integrations/map.js +43 -0
  65. package/dist/integrations/map.js.map +1 -0
  66. package/dist/integrations/profile-key.d.ts +19 -0
  67. package/dist/integrations/profile-key.js +35 -0
  68. package/dist/integrations/profile-key.js.map +1 -0
  69. package/dist/integrations/read-only-postgres-query.d.ts +2 -0
  70. package/dist/integrations/read-only-postgres-query.js +164 -0
  71. package/dist/integrations/read-only-postgres-query.js.map +1 -0
  72. package/dist/main.d.ts +2 -0
  73. package/dist/main.js +5 -0
  74. package/dist/main.js.map +1 -0
  75. package/dist/orchestrator/client.d.ts +62 -0
  76. package/dist/orchestrator/client.js +160 -0
  77. package/dist/orchestrator/client.js.map +1 -0
  78. package/dist/playwright/ensure-chromium.d.ts +24 -0
  79. package/dist/playwright/ensure-chromium.js +60 -0
  80. package/dist/playwright/ensure-chromium.js.map +1 -0
  81. package/dist/preview/capture-screenshot.d.ts +67 -0
  82. package/dist/preview/capture-screenshot.js +179 -0
  83. package/dist/preview/capture-screenshot.js.map +1 -0
  84. package/dist/preview/viewer-url.d.ts +82 -0
  85. package/dist/preview/viewer-url.js +130 -0
  86. package/dist/preview/viewer-url.js.map +1 -0
  87. package/dist/process/fault-barrier.d.ts +55 -0
  88. package/dist/process/fault-barrier.js +113 -0
  89. package/dist/process/fault-barrier.js.map +1 -0
  90. package/dist/sabs/agent-facing-text.d.ts +35 -0
  91. package/dist/sabs/agent-facing-text.js +165 -0
  92. package/dist/sabs/agent-facing-text.js.map +1 -0
  93. package/dist/sabs/app-state.d.ts +126 -0
  94. package/dist/sabs/app-state.js +332 -0
  95. package/dist/sabs/app-state.js.map +1 -0
  96. package/dist/sabs/awaited-decision.d.ts +47 -0
  97. package/dist/sabs/awaited-decision.js +124 -0
  98. package/dist/sabs/awaited-decision.js.map +1 -0
  99. package/dist/sabs/browser-context.d.ts +53 -0
  100. package/dist/sabs/browser-context.js +92 -0
  101. package/dist/sabs/browser-context.js.map +1 -0
  102. package/dist/sabs/editor-client-methods.d.ts +164 -0
  103. package/dist/sabs/editor-client-methods.js +750 -0
  104. package/dist/sabs/editor-client-methods.js.map +1 -0
  105. package/dist/sabs/editor-socket.d.ts +84 -0
  106. package/dist/sabs/editor-socket.js +64 -0
  107. package/dist/sabs/editor-socket.js.map +1 -0
  108. package/dist/sabs/recent-tool-runs.d.ts +14 -0
  109. package/dist/sabs/recent-tool-runs.js +61 -0
  110. package/dist/sabs/recent-tool-runs.js.map +1 -0
  111. package/dist/sabs/session-peer.d.ts +392 -0
  112. package/dist/sabs/session-peer.js +11 -0
  113. package/dist/sabs/session-peer.js.map +1 -0
  114. package/dist/sabs/streamed-reply.d.ts +42 -0
  115. package/dist/sabs/streamed-reply.js +110 -0
  116. package/dist/sabs/streamed-reply.js.map +1 -0
  117. package/dist/sabs/turn-collector.d.ts +169 -0
  118. package/dist/sabs/turn-collector.js +506 -0
  119. package/dist/sabs/turn-collector.js.map +1 -0
  120. package/dist/sabs/websocket-session-peer.d.ts +540 -0
  121. package/dist/sabs/websocket-session-peer.js +3289 -0
  122. package/dist/sabs/websocket-session-peer.js.map +1 -0
  123. package/dist/security/constant-time.d.ts +9 -0
  124. package/dist/security/constant-time.js +13 -0
  125. package/dist/security/constant-time.js.map +1 -0
  126. package/dist/server/client.d.ts +405 -0
  127. package/dist/server/client.js +684 -0
  128. package/dist/server/client.js.map +1 -0
  129. package/dist/server/identity-reads.d.ts +76 -0
  130. package/dist/server/identity-reads.js +209 -0
  131. package/dist/server/identity-reads.js.map +1 -0
  132. package/dist/start.d.ts +24 -0
  133. package/dist/start.js +81 -0
  134. package/dist/start.js.map +1 -0
  135. package/dist/stores/memory.d.ts +42 -0
  136. package/dist/stores/memory.js +121 -0
  137. package/dist/stores/memory.js.map +1 -0
  138. package/dist/stores/types.d.ts +74 -0
  139. package/dist/stores/types.js +11 -0
  140. package/dist/stores/types.js.map +1 -0
  141. package/dist/telemetry/mcp-client.d.ts +22 -0
  142. package/dist/telemetry/mcp-client.js +140 -0
  143. package/dist/telemetry/mcp-client.js.map +1 -0
  144. package/dist/telemetry/metrics.d.ts +41 -0
  145. package/dist/telemetry/metrics.js +103 -0
  146. package/dist/telemetry/metrics.js.map +1 -0
  147. package/dist/telemetry/runtime.d.ts +9 -0
  148. package/dist/telemetry/runtime.js +118 -0
  149. package/dist/telemetry/runtime.js.map +1 -0
  150. package/dist/transports/mcp/admin-tools.d.ts +56 -0
  151. package/dist/transports/mcp/admin-tools.js +252 -0
  152. package/dist/transports/mcp/admin-tools.js.map +1 -0
  153. package/dist/transports/mcp/app-status-html.d.ts +11 -0
  154. package/dist/transports/mcp/app-status-html.js +899 -0
  155. package/dist/transports/mcp/app-status-html.js.map +1 -0
  156. package/dist/transports/mcp/client-presentation.d.ts +16 -0
  157. package/dist/transports/mcp/client-presentation.js +13 -0
  158. package/dist/transports/mcp/client-presentation.js.map +1 -0
  159. package/dist/transports/mcp/cowork-editor-url.d.ts +6 -0
  160. package/dist/transports/mcp/cowork-editor-url.js +10 -0
  161. package/dist/transports/mcp/cowork-editor-url.js.map +1 -0
  162. package/dist/transports/mcp/decision-card-html.d.ts +26 -0
  163. package/dist/transports/mcp/decision-card-html.js +876 -0
  164. package/dist/transports/mcp/decision-card-html.js.map +1 -0
  165. package/dist/transports/mcp/decision-elicitation.d.ts +116 -0
  166. package/dist/transports/mcp/decision-elicitation.js +292 -0
  167. package/dist/transports/mcp/decision-elicitation.js.map +1 -0
  168. package/dist/transports/mcp/dispatch-probe.d.ts +24 -0
  169. package/dist/transports/mcp/dispatch-probe.js +48 -0
  170. package/dist/transports/mcp/dispatch-probe.js.map +1 -0
  171. package/dist/transports/mcp/editor-document-probe.d.ts +4 -0
  172. package/dist/transports/mcp/editor-document-probe.js +35 -0
  173. package/dist/transports/mcp/editor-document-probe.js.map +1 -0
  174. package/dist/transports/mcp/editor-integration-setup-url.d.ts +8 -0
  175. package/dist/transports/mcp/editor-integration-setup-url.js +23 -0
  176. package/dist/transports/mcp/editor-integration-setup-url.js.map +1 -0
  177. package/dist/transports/mcp/format-tool-content.d.ts +20 -0
  178. package/dist/transports/mcp/format-tool-content.js +89 -0
  179. package/dist/transports/mcp/format-tool-content.js.map +1 -0
  180. package/dist/transports/mcp/instructions/index.d.ts +23 -0
  181. package/dist/transports/mcp/instructions/index.js +81 -0
  182. package/dist/transports/mcp/instructions/index.js.map +1 -0
  183. package/dist/transports/mcp/instructions/result.d.ts +18 -0
  184. package/dist/transports/mcp/instructions/result.js +58 -0
  185. package/dist/transports/mcp/instructions/result.js.map +1 -0
  186. package/dist/transports/mcp/instructions/tools/ask-user.d.ts +2 -0
  187. package/dist/transports/mcp/instructions/tools/ask-user.js +17 -0
  188. package/dist/transports/mcp/instructions/tools/ask-user.js.map +1 -0
  189. package/dist/transports/mcp/instructions/tools/check-app-progress.d.ts +3 -0
  190. package/dist/transports/mcp/instructions/tools/check-app-progress.js +75 -0
  191. package/dist/transports/mcp/instructions/tools/check-app-progress.js.map +1 -0
  192. package/dist/transports/mcp/instructions/tools/check-publish-progress.d.ts +3 -0
  193. package/dist/transports/mcp/instructions/tools/check-publish-progress.js +23 -0
  194. package/dist/transports/mcp/instructions/tools/check-publish-progress.js.map +1 -0
  195. package/dist/transports/mcp/instructions/tools/copy.d.ts +14 -0
  196. package/dist/transports/mcp/instructions/tools/copy.js +35 -0
  197. package/dist/transports/mcp/instructions/tools/copy.js.map +1 -0
  198. package/dist/transports/mcp/instructions/tools/create-integration.d.ts +4 -0
  199. package/dist/transports/mcp/instructions/tools/create-integration.js +41 -0
  200. package/dist/transports/mcp/instructions/tools/create-integration.js.map +1 -0
  201. package/dist/transports/mcp/instructions/tools/edit-app.d.ts +2 -0
  202. package/dist/transports/mcp/instructions/tools/edit-app.js +18 -0
  203. package/dist/transports/mcp/instructions/tools/edit-app.js.map +1 -0
  204. package/dist/transports/mcp/instructions/tools/get-app.d.ts +3 -0
  205. package/dist/transports/mcp/instructions/tools/get-app.js +47 -0
  206. package/dist/transports/mcp/instructions/tools/get-app.js.map +1 -0
  207. package/dist/transports/mcp/instructions/tools/get-integration-metadata.d.ts +2 -0
  208. package/dist/transports/mcp/instructions/tools/get-integration-metadata.js +13 -0
  209. package/dist/transports/mcp/instructions/tools/get-integration-metadata.js.map +1 -0
  210. package/dist/transports/mcp/instructions/tools/index.d.ts +7 -0
  211. package/dist/transports/mcp/instructions/tools/index.js +26 -0
  212. package/dist/transports/mcp/instructions/tools/index.js.map +1 -0
  213. package/dist/transports/mcp/instructions/tools/preview-app.d.ts +3 -0
  214. package/dist/transports/mcp/instructions/tools/preview-app.js +14 -0
  215. package/dist/transports/mcp/instructions/tools/preview-app.js.map +1 -0
  216. package/dist/transports/mcp/instructions/tools/publish-app.d.ts +3 -0
  217. package/dist/transports/mcp/instructions/tools/publish-app.js +23 -0
  218. package/dist/transports/mcp/instructions/tools/publish-app.js.map +1 -0
  219. package/dist/transports/mcp/instructions/tools/start-app.d.ts +2 -0
  220. package/dist/transports/mcp/instructions/tools/start-app.js +22 -0
  221. package/dist/transports/mcp/instructions/tools/start-app.js.map +1 -0
  222. package/dist/transports/mcp/instructions/tools/upload-artifact.d.ts +2 -0
  223. package/dist/transports/mcp/instructions/tools/upload-artifact.js +13 -0
  224. package/dist/transports/mcp/instructions/tools/upload-artifact.js.map +1 -0
  225. package/dist/transports/mcp/mcp-app-brand-css.d.ts +1 -0
  226. package/dist/transports/mcp/mcp-app-brand-css.js +180 -0
  227. package/dist/transports/mcp/mcp-app-brand-css.js.map +1 -0
  228. package/dist/transports/mcp/mount.d.ts +22 -0
  229. package/dist/transports/mcp/mount.js +1040 -0
  230. package/dist/transports/mcp/mount.js.map +1 -0
  231. package/dist/transports/mcp/native-browser-presence.d.ts +45 -0
  232. package/dist/transports/mcp/native-browser-presence.js +158 -0
  233. package/dist/transports/mcp/native-browser-presence.js.map +1 -0
  234. package/dist/transports/mcp/plan-approval.d.ts +38 -0
  235. package/dist/transports/mcp/plan-approval.js +175 -0
  236. package/dist/transports/mcp/plan-approval.js.map +1 -0
  237. package/dist/transports/mcp/progress-notifier.d.ts +39 -0
  238. package/dist/transports/mcp/progress-notifier.js +52 -0
  239. package/dist/transports/mcp/progress-notifier.js.map +1 -0
  240. package/dist/transports/mcp/session-directory.d.ts +7 -0
  241. package/dist/transports/mcp/session-directory.js +18 -0
  242. package/dist/transports/mcp/session-directory.js.map +1 -0
  243. package/dist/transports/mcp/tool-names.d.ts +2 -0
  244. package/dist/transports/mcp/tool-names.js +2 -0
  245. package/dist/transports/mcp/tool-names.js.map +1 -0
  246. package/package.json +78 -0
  247. package/skills/superblocks-build/SKILL.md +59 -0
  248. package/skills/superblocks-import/SKILL.md +88 -0
@@ -0,0 +1,876 @@
1
+ import { MCP_APP_BRAND_CSS } from "./mcp-app-brand-css.js";
2
+ /**
3
+ * Self-contained MCP App HTML for the plan or question Superblocks stopped on.
4
+ *
5
+ * A host with form elicitation gets a native picker and never opens this. This
6
+ * is for the hosts that have none - Claude Desktop today - where the whole
7
+ * decision UX would otherwise be the model choosing to write the plan out and
8
+ * ask. It does that inconsistently, so the card puts the plan on screen with
9
+ * Build it / Change something next to it.
10
+ *
11
+ * The answer travels as `ui/message`, not a direct `edit_app` call. A plan
12
+ * approval first consumes a private capability through an app-only tool, then
13
+ * `ui/message` posts the answer as the user's own turn so the agent loop
14
+ * continues exactly as it would have had they typed it.
15
+ *
16
+ * The card is an accelerator, never the only route: the decision is in the tool
17
+ * result as data too, and a host that will not deliver `ui/message` is told to
18
+ * answer in the chat rather than left with a dead form.
19
+ *
20
+ * Speaks the MCP Apps postMessage dialect without bundling ext-apps into the
21
+ * card (hosts cache UI resources; keep this file small and inline). Bump the
22
+ * resource URI when the HTML changes so Claude Desktop refreshes its cache.
23
+ */
24
+ export const PLAN_APPROVAL_TOKEN_META_KEY = "superblocks/plan-approval-token";
25
+ export const CONFIRM_PLAN_APPROVAL_TOOL = "confirm_plan_approval";
26
+ export const APP_DECISION_RESOURCE_URI = "ui://gateway/decision-v20.html";
27
+ export const APP_DECISION_HTML = `<!DOCTYPE html>
28
+ <html lang="en">
29
+ <head>
30
+ <meta charset="utf-8" />
31
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
32
+ <title>Superblocks needs an answer</title>
33
+ <style>
34
+ h1 {
35
+ margin: 0;
36
+ font-size: var(--font-text-md-size, 14px);
37
+ font-weight: var(--font-weight-semibold, 600);
38
+ }
39
+ .meta {
40
+ color: var(--sb-app-text-tertiary);
41
+ font-size: var(--font-text-xs-size, 12px);
42
+ }
43
+ .reply {
44
+ display: none;
45
+ color: var(--sb-app-text-secondary);
46
+ }
47
+ .reply.shown {
48
+ display: block;
49
+ }
50
+ .plan {
51
+ display: none;
52
+ max-height: 340px;
53
+ margin: 0;
54
+ overflow: auto;
55
+ padding: 10px;
56
+ border: var(--border-width-regular, 1px) solid var(--sb-app-border);
57
+ border-radius: var(--border-radius-md, 8px);
58
+ background: var(--sb-app-background-subtle);
59
+ font-size: var(--font-text-xs-size, 12px);
60
+ word-break: break-word;
61
+ }
62
+ .plan.shown {
63
+ display: block;
64
+ }
65
+ .plan > :first-child,
66
+ .question > :first-child {
67
+ margin-top: 0;
68
+ }
69
+ .plan > :last-child,
70
+ .question > :last-child {
71
+ margin-bottom: 0;
72
+ }
73
+ .plan h1,
74
+ .plan h2,
75
+ .plan h3,
76
+ .plan p,
77
+ .question h1,
78
+ .question h2,
79
+ .question h3,
80
+ .question p {
81
+ margin: 10px 0;
82
+ }
83
+ .plan h1,
84
+ .plan h2,
85
+ .plan h3,
86
+ .question h1,
87
+ .question h2,
88
+ .question h3 {
89
+ font-size: inherit;
90
+ font-weight: var(--font-weight-semibold, 600);
91
+ }
92
+ .plan ul,
93
+ .plan ol,
94
+ .question ul,
95
+ .question ol {
96
+ margin: 10px 0;
97
+ padding-left: 20px;
98
+ }
99
+ .plan blockquote,
100
+ .question blockquote {
101
+ margin: 10px 0;
102
+ padding-left: 10px;
103
+ border-left: 3px solid var(--sb-app-border);
104
+ color: var(--sb-app-text-secondary);
105
+ }
106
+ .plan pre,
107
+ .question pre {
108
+ overflow: auto;
109
+ padding: 8px;
110
+ border-radius: var(--border-radius-md, 8px);
111
+ background: var(--sb-app-background);
112
+ }
113
+ .plan a,
114
+ .question a {
115
+ color: var(--sb-app-info-text);
116
+ }
117
+ .entity-tag {
118
+ display: inline-flex;
119
+ align-items: center;
120
+ padding: 0 4px;
121
+ max-width: 100%;
122
+ overflow-wrap: anywhere;
123
+ border: var(--border-width-regular, 1px) solid var(--sb-app-border);
124
+ border-radius: 4px;
125
+ background: var(--sb-app-background);
126
+ color: var(--sb-app-info-text);
127
+ font-weight: 400;
128
+ line-height: 18px;
129
+ vertical-align: middle;
130
+ white-space: normal;
131
+ }
132
+ .task {
133
+ display: inline-flex;
134
+ align-items: center;
135
+ gap: 6px;
136
+ }
137
+ .task input {
138
+ margin: 0;
139
+ }
140
+ .plan code,
141
+ .question code,
142
+ button code {
143
+ font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
144
+ }
145
+ .question {
146
+ display: none;
147
+ overflow-wrap: anywhere;
148
+ font-weight: var(--font-weight-medium, 500);
149
+ }
150
+ .question.shown {
151
+ display: block;
152
+ }
153
+ .actions {
154
+ display: none;
155
+ flex-wrap: wrap;
156
+ gap: 8px;
157
+ }
158
+ .actions.shown {
159
+ display: flex;
160
+ }
161
+ #options {
162
+ flex-direction: column;
163
+ flex-wrap: nowrap;
164
+ }
165
+ #options > .option-button {
166
+ width: 100%;
167
+ overflow-wrap: anywhere;
168
+ text-align: left;
169
+ }
170
+ .refine {
171
+ display: none;
172
+ flex-direction: column;
173
+ gap: 8px;
174
+ }
175
+ .refine.shown {
176
+ display: flex;
177
+ }
178
+ textarea {
179
+ width: 100%;
180
+ box-sizing: border-box;
181
+ min-height: 64px;
182
+ padding: 8px;
183
+ border: var(--border-width-regular, 1px) solid var(--sb-app-border);
184
+ border-radius: var(--border-radius-md, 8px);
185
+ background: var(--sb-app-background);
186
+ color: var(--sb-app-text);
187
+ font: inherit;
188
+ resize: vertical;
189
+ }
190
+ .note {
191
+ color: var(--sb-app-text-secondary);
192
+ font-size: var(--font-text-xs-size, 12px);
193
+ }
194
+ ${MCP_APP_BRAND_CSS}
195
+ </style>
196
+ </head>
197
+ <body>
198
+ <div class="card">
199
+ <h1 id="heading">Superblocks</h1>
200
+ <div id="appId" class="meta"></div>
201
+ <div id="reply" class="reply"></div>
202
+ <div id="plan" class="plan"></div>
203
+ <div id="question" class="question"></div>
204
+ <div id="options" class="actions"></div>
205
+ <div id="planActions" class="actions">
206
+ <button id="approve" class="button-primary" type="button">Build it</button>
207
+ <button id="refine" class="button-secondary" type="button">Change something</button>
208
+ </div>
209
+ <div id="refineBox" class="refine">
210
+ <textarea id="feedback" placeholder="What should change?"></textarea>
211
+ <button id="sendRefine" class="button-primary" type="button">Send</button>
212
+ </div>
213
+ <div id="note" class="note" aria-live="polite"></div>
214
+ </div>
215
+ <script>
216
+ (() => {
217
+ const PROTOCOL_VERSION = "2026-01-26";
218
+ let nextId = 1;
219
+ const pending = new Map();
220
+ let applicationId = "";
221
+ let appName = "";
222
+ let reply = "";
223
+ let decision = null;
224
+ let status = "";
225
+ let refining = false;
226
+ let sending = false;
227
+ let answered = false;
228
+ let approvalToken = "";
229
+ let optionButtons = [];
230
+ let lastHeight = 0;
231
+
232
+ function post(message) {
233
+ window.parent.postMessage(message, "*");
234
+ }
235
+
236
+ function notify(method, params) {
237
+ post({ jsonrpc: "2.0", method, params });
238
+ }
239
+
240
+ function request(method, params) {
241
+ const id = nextId++;
242
+ return new Promise((resolve, reject) => {
243
+ pending.set(id, { resolve, reject });
244
+ post({ jsonrpc: "2.0", id, method, params });
245
+ });
246
+ }
247
+
248
+ function element(id) {
249
+ return document.getElementById(id);
250
+ }
251
+
252
+ function show(id, on) {
253
+ const node = element(id);
254
+ if (node && node.classList) {
255
+ node.classList.toggle("shown", on);
256
+ }
257
+ }
258
+
259
+ // Hosts size the card from this notification alone; without it the card
260
+ // is laid out at zero height and never appears.
261
+ function reportSize() {
262
+ const height = Math.ceil(document.documentElement.scrollHeight || 0);
263
+ if (height <= 0 || height === lastHeight) {
264
+ return;
265
+ }
266
+ lastHeight = height;
267
+ notify("ui/notifications/size-changed", {
268
+ height,
269
+ width: Math.ceil(window.innerWidth || 0),
270
+ });
271
+ }
272
+
273
+ function note(text) {
274
+ element("note").textContent = text;
275
+ show("note", Boolean(text));
276
+ reportSize();
277
+ }
278
+
279
+ function applyHostContext(context) {
280
+ if (!context || typeof context !== "object") {
281
+ return;
282
+ }
283
+ const root = document.documentElement;
284
+ if (context.theme === "light" || context.theme === "dark") {
285
+ root.setAttribute("data-theme", context.theme);
286
+ root.style.colorScheme = context.theme;
287
+ }
288
+ const variables = context.styles && context.styles.variables;
289
+ if (variables && root.style) {
290
+ for (const name of Object.keys(variables)) {
291
+ const value = variables[name];
292
+ if (typeof value === "string") {
293
+ root.style.setProperty(name, value);
294
+ }
295
+ }
296
+ }
297
+ const fonts = context.styles && context.styles.css?.fonts;
298
+ if (typeof fonts === "string") {
299
+ let fontStyle = document.getElementById("__mcp-host-fonts");
300
+ if (!fontStyle) {
301
+ fontStyle = document.createElement("style");
302
+ fontStyle.id = "__mcp-host-fonts";
303
+ document.head.appendChild(fontStyle);
304
+ }
305
+ fontStyle.textContent = fonts;
306
+ }
307
+ reportSize();
308
+ }
309
+
310
+ function setBusy(on) {
311
+ element("approve").disabled = on;
312
+ element("refine").disabled = on;
313
+ element("sendRefine").disabled = on;
314
+ for (const button of optionButtons) {
315
+ button.disabled = on;
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Posts the answer as the user's own turn.
321
+ *
322
+ * Not tools/call: calling edit_app from in here starts a build the host
323
+ * agent never learns about, so nothing polls it and nothing is relayed.
324
+ */
325
+ function answer(text) {
326
+ if (!text || sending || answered) {
327
+ return;
328
+ }
329
+ sending = true;
330
+ setBusy(true);
331
+ note("Sending your answer…");
332
+ request("ui/message", {
333
+ content: [{ text: text, type: "text" }],
334
+ role: "user",
335
+ })
336
+ .then((result) => {
337
+ sending = false;
338
+ if (result && result.isError) {
339
+ refused();
340
+ return;
341
+ }
342
+ answered = true;
343
+ setBusy(true);
344
+ // The host taking the message is not the same as the user's turn
345
+ // going anywhere: Claude Desktop leaves it in the composer as a
346
+ // draft. Claiming it was sent strands the user on a build that is
347
+ // waiting for their enter key.
348
+ note("Your answer is in the chat — press enter there to send it.");
349
+ })
350
+ .catch(refused);
351
+ }
352
+
353
+ function refused() {
354
+ sending = false;
355
+ setBusy(false);
356
+ note(
357
+ "This host would not take your answer from the card — reply in the chat instead.",
358
+ );
359
+ }
360
+
361
+ function approvalRefused() {
362
+ sending = false;
363
+ setBusy(false);
364
+ note(
365
+ "This host could not verify your approval - approve this plan in the Superblocks editor instead.",
366
+ );
367
+ }
368
+
369
+ function approve() {
370
+ if (sending || answered) {
371
+ return;
372
+ }
373
+ if (!approvalToken) {
374
+ approvalRefused();
375
+ return;
376
+ }
377
+ sending = true;
378
+ setBusy(true);
379
+ note("Confirming your approval...");
380
+ request("tools/call", {
381
+ arguments: { approvalToken: approvalToken },
382
+ name: "${CONFIRM_PLAN_APPROVAL_TOOL}",
383
+ })
384
+ .then((result) => {
385
+ sending = false;
386
+ if (result && result.isError) {
387
+ approvalRefused();
388
+ return;
389
+ }
390
+ answer("Build it — approve the Superblocks plan as written.");
391
+ })
392
+ .catch(approvalRefused);
393
+ }
394
+
395
+ function renderOptions(options) {
396
+ const host = element("options");
397
+ host.replaceChildren();
398
+ optionButtons = [];
399
+ options.forEach((option, index) => {
400
+ const button = document.createElement("button");
401
+ button.id = "option-" + index;
402
+ button.className = "button-secondary option-button";
403
+ button.type = "button";
404
+ button.innerHTML = markdownInline(option, false);
405
+ // Verbatim: an option Superblocks did not offer reaches it as a
406
+ // prompt answering a question it never asked.
407
+ button.addEventListener("click", () => answer(option));
408
+ host.appendChild(button);
409
+ optionButtons.push(button);
410
+ });
411
+ show("options", options.length > 0);
412
+ }
413
+
414
+ function waitingNote() {
415
+ if (status === "building") {
416
+ return "Superblocks is still building — nothing to answer yet.";
417
+ }
418
+ // Something opened this card, so "nothing is waiting on you" is a dead
419
+ // end: say where the answer to that actually is.
420
+ return "Nothing to answer here — the chat has the latest.";
421
+ }
422
+
423
+ function escapeHtml(text) {
424
+ return String(text).replace(/[&<>"']/g, (character) => {
425
+ return {
426
+ "&": "&amp;",
427
+ "<": "&lt;",
428
+ ">": "&gt;",
429
+ '"': "&quot;",
430
+ "'": "&#39;",
431
+ }[character];
432
+ });
433
+ }
434
+
435
+ function markdownInline(text, allowLinks = true) {
436
+ const codeDelimiter = String.fromCharCode(96);
437
+ const emphasis = (text) =>
438
+ text
439
+ .replace(/\\*\\*([^*]+)\\*\\*/g, "<strong>$1</strong>")
440
+ .replace(/__([^_]+)__/g, "<strong>$1</strong>")
441
+ .replace(/(^|[^*])\\*([^*]+)\\*(?!\\*)/g, "$1<em>$2</em>")
442
+ .replace(
443
+ /(^|[^A-Za-z0-9_])_([^_]+)_(?![A-Za-z0-9_])/g,
444
+ "$1<em>$2</em>",
445
+ );
446
+ const safeLink = (url) => {
447
+ try {
448
+ const parsed = new URL(url);
449
+ return parsed.protocol === "https:" && Boolean(parsed.hostname);
450
+ } catch {
451
+ return false;
452
+ }
453
+ };
454
+ const entities = /@((?:(?!\\[id=)[^@\\r\\n])+?(?<!\\s))\\[id=[^\\]\\r\\n]+\\]/gu;
455
+ const links = /\\[([^\\]]+)\\]\\(([^\\s)]+)\\)/g;
456
+ const renderLinks = (value, allowLinks) => {
457
+ const output = [];
458
+ let offset = 0;
459
+ const text = String(value);
460
+ for (const match of text.matchAll(links)) {
461
+ const index = match.index ?? 0;
462
+ if (text[index - 1] === "!") {
463
+ continue;
464
+ }
465
+ output.push(emphasis(escapeHtml(text.slice(offset, index))));
466
+ const label = match[1];
467
+ const url = match[2];
468
+ if (safeLink(url)) {
469
+ output.push(
470
+ allowLinks
471
+ ? '<a href="' +
472
+ escapeHtml(url) +
473
+ '" target="_blank" rel="noopener noreferrer">' +
474
+ markdownInline(label, false) +
475
+ "</a>"
476
+ : markdownInline(label, false),
477
+ );
478
+ } else {
479
+ output.push(emphasis(escapeHtml(match[0])));
480
+ }
481
+ offset = index + match[0].length;
482
+ }
483
+ output.push(emphasis(escapeHtml(text.slice(offset))));
484
+ return output.join("");
485
+ };
486
+ const renderText = (value, allowLinks) => {
487
+ const text = String(value);
488
+ let placeholderDelimiter = String.fromCharCode(0);
489
+ while (text.includes(placeholderDelimiter)) {
490
+ placeholderDelimiter += String.fromCharCode(0);
491
+ }
492
+ const linkDestinations = Array.from(text.matchAll(links), (match) => {
493
+ const start = (match.index ?? 0) + match[1].length + 3;
494
+ return { start, end: start + match[2].length };
495
+ });
496
+ const entityTags = [];
497
+ const tokenized = text.replace(entities, (match, label, index) => {
498
+ if (
499
+ linkDestinations.some(
500
+ ({ start, end }) => index >= start && index < end,
501
+ )
502
+ ) {
503
+ return match;
504
+ }
505
+ const placeholder =
506
+ placeholderDelimiter + entityTags.length + placeholderDelimiter;
507
+ entityTags.push(
508
+ '<span class="entity-tag">' + escapeHtml(label) + "</span>",
509
+ );
510
+ return placeholder;
511
+ });
512
+ return entityTags.reduce(
513
+ (html, tag, index) =>
514
+ html.replace(
515
+ placeholderDelimiter + index + placeholderDelimiter,
516
+ () => tag,
517
+ ),
518
+ renderLinks(tokenized, allowLinks),
519
+ );
520
+ };
521
+ return String(text)
522
+ .split(/(\\x60[^\\x60]+\\x60)/)
523
+ .map((part) =>
524
+ part.startsWith(codeDelimiter) && part.endsWith(codeDelimiter)
525
+ ? "<code>" + escapeHtml(part.slice(1, -1)) + "</code>"
526
+ : renderText(part, allowLinks),
527
+ )
528
+ .join("");
529
+ }
530
+
531
+ function markdownHtml(markdown) {
532
+ const lines = String(markdown).replace(/\\r/g, "").split("\\n");
533
+ const output = [];
534
+ const lists = [];
535
+ let paragraph = [];
536
+ const closeParagraph = () => {
537
+ if (paragraph.length > 0) {
538
+ output.push("<p>" + markdownInline(paragraph.join(" ")) + "</p>");
539
+ paragraph = [];
540
+ }
541
+ };
542
+ const closeList = () => {
543
+ const list = lists.pop();
544
+ if (!list) {
545
+ return;
546
+ }
547
+ if (list.open) {
548
+ output.push("</li>");
549
+ }
550
+ output.push("</" + list.tag + ">");
551
+ };
552
+ const closeLists = () => {
553
+ while (lists.length > 0) {
554
+ closeList();
555
+ }
556
+ };
557
+ const listItem = (line) => {
558
+ const match = /^(\\s*)([-*+]|\\d+\\.)\\s+(.+)$/.exec(line);
559
+ if (!match) {
560
+ return undefined;
561
+ }
562
+ return {
563
+ content: match[3],
564
+ indent: match[1].replace(/\\t/g, " ").length,
565
+ tag: /\\d+\\./.test(match[2]) ? "ol" : "ul",
566
+ };
567
+ };
568
+ const renderListItem = (item) => {
569
+ while (
570
+ lists.length > 0 &&
571
+ item.indent < lists[lists.length - 1].indent
572
+ ) {
573
+ closeList();
574
+ }
575
+ let list = lists[lists.length - 1];
576
+ if (
577
+ !list ||
578
+ item.indent > list.indent ||
579
+ (item.indent === list.indent && item.tag !== list.tag)
580
+ ) {
581
+ if (list && item.indent === list.indent) {
582
+ closeList();
583
+ }
584
+ output.push("<" + item.tag + ">");
585
+ list = { indent: item.indent, open: false, tag: item.tag };
586
+ lists.push(list);
587
+ }
588
+ if (list.open) {
589
+ output.push("</li>");
590
+ }
591
+ const task = /^\\[([ xX])\\]\\s+(.+)$/.exec(item.content);
592
+ output.push(
593
+ "<li>" +
594
+ (task
595
+ ? '<label class="task"><input type="checkbox" disabled' +
596
+ (task[1].toLowerCase() === "x" ? " checked" : "") +
597
+ ">" +
598
+ markdownInline(task[2]) +
599
+ "</label>"
600
+ : markdownInline(item.content)),
601
+ );
602
+ list.open = true;
603
+ };
604
+
605
+ for (let index = 0; index < lines.length; index += 1) {
606
+ const line = lines[index];
607
+ const fence = /^\\x60{3}[^\\x60]*\\s*$/.exec(line);
608
+ if (fence) {
609
+ closeParagraph();
610
+ closeLists();
611
+ const code = [];
612
+ while (
613
+ index + 1 < lines.length &&
614
+ !/^\\x60{3}\\s*$/.test(lines[index + 1])
615
+ ) {
616
+ index += 1;
617
+ code.push(lines[index]);
618
+ }
619
+ if (index + 1 < lines.length) {
620
+ index += 1;
621
+ }
622
+ output.push(
623
+ "<pre><code>" + escapeHtml(code.join("\\n")) + "</code></pre>",
624
+ );
625
+ continue;
626
+ }
627
+ const heading = /^(#{1,3})\\s+(.+?)\\s*$/.exec(line);
628
+ const quote = /^>\\s?(.*)$/.exec(line);
629
+ const item = listItem(line);
630
+ const rule = /^(---+|\\*\\*\\*+|___+)$/.test(line.trim());
631
+ if (heading) {
632
+ closeParagraph();
633
+ closeLists();
634
+ const level = heading[1].length;
635
+ output.push("<h" + level + ">" + markdownInline(heading[2]) + "</h" + level + ">");
636
+ } else if (quote) {
637
+ closeParagraph();
638
+ closeLists();
639
+ const quoted = [];
640
+ while (index < lines.length) {
641
+ const next = /^>\\s?(.*)$/.exec(lines[index]);
642
+ if (!next) {
643
+ break;
644
+ }
645
+ quoted.push(next[1]);
646
+ index += 1;
647
+ }
648
+ index -= 1;
649
+ output.push("<blockquote>" + markdownHtml(quoted.join("\\n")) + "</blockquote>");
650
+ } else if (item) {
651
+ closeParagraph();
652
+ renderListItem(item);
653
+ } else if (rule) {
654
+ closeParagraph();
655
+ closeLists();
656
+ output.push("<hr>");
657
+ } else if (line.trim()) {
658
+ closeLists();
659
+ paragraph.push(line.trim());
660
+ } else {
661
+ closeParagraph();
662
+ closeLists();
663
+ }
664
+ }
665
+ closeParagraph();
666
+ closeLists();
667
+ return output.join("");
668
+ }
669
+
670
+ function render() {
671
+ const waiting = status === "needs_decision";
672
+ const plan =
673
+ waiting && decision && decision.kind === "plan" ? decision : null;
674
+ const choice =
675
+ waiting && decision && decision.kind === "multi_choice"
676
+ ? decision
677
+ : null;
678
+
679
+ element("heading").textContent = plan
680
+ ? "Superblocks proposed a plan"
681
+ : choice
682
+ ? "Superblocks has a question"
683
+ : waiting
684
+ ? "Superblocks is waiting on you"
685
+ : "Superblocks";
686
+ element("appId").textContent = appName || applicationId;
687
+ // Superblocks narrates its whole working session into the reply. Once
688
+ // there is a plan or a question, that narration is preamble in front
689
+ // of the thing being asked, so it is dropped: the ask is the ask. It
690
+ // survives only when there is nothing structured, where the reply is
691
+ // itself the whole question and hiding it leaves a blank card.
692
+ const narrationOnly = Boolean(plan || choice);
693
+ element("reply").textContent = narrationOnly ? "" : reply;
694
+ show("reply", Boolean(reply) && !narrationOnly);
695
+ element("plan").innerHTML = plan ? markdownHtml(plan.plan) : "";
696
+ show("plan", Boolean(plan));
697
+ element("question").innerHTML = choice
698
+ ? markdownHtml(choice.question)
699
+ : "";
700
+ show("question", Boolean(choice));
701
+ show("planActions", Boolean(plan));
702
+ renderOptions(choice ? choice.options : []);
703
+ // A turn can stop waiting on the user having streamed its plan or
704
+ // question as chat text, leaving nothing structured to lay out. The
705
+ // reply is then the whole ask, so free text is the only honest form.
706
+ show("refineBox", plan ? refining : waiting && !choice);
707
+ setBusy(answered || sending);
708
+ if (!answered && !sending) {
709
+ note(waiting ? "" : waitingNote());
710
+ }
711
+ reportSize();
712
+ }
713
+
714
+ function applyPayload(payload) {
715
+ let value = payload;
716
+ if (typeof value === "string") {
717
+ try {
718
+ value = JSON.parse(value);
719
+ } catch (error) {
720
+ return;
721
+ }
722
+ }
723
+ if (!value || typeof value !== "object") {
724
+ return;
725
+ }
726
+ if (Array.isArray(value.content)) {
727
+ applyContent(value.content);
728
+ if (value.structuredContent) {
729
+ applyPayload(value.structuredContent);
730
+ }
731
+ return;
732
+ }
733
+ if (value.result && typeof value.result === "object") {
734
+ applyPayload(value.result);
735
+ return;
736
+ }
737
+ if (value.kind === "ok" && value.value) {
738
+ value = value.value;
739
+ }
740
+ if (typeof value.applicationId === "string") {
741
+ applicationId = value.applicationId;
742
+ }
743
+ if (typeof value.name === "string") {
744
+ appName = value.name;
745
+ }
746
+ if (typeof value.reply === "string") {
747
+ reply = value.reply;
748
+ }
749
+ if (typeof value.status === "string") {
750
+ status = value.status;
751
+ }
752
+ if ("decision" in value) {
753
+ decision =
754
+ value.decision && typeof value.decision === "object"
755
+ ? value.decision
756
+ : null;
757
+ }
758
+ render();
759
+ }
760
+
761
+ function applyContent(content) {
762
+ for (const part of content || []) {
763
+ if (part && part.type === "text" && typeof part.text === "string") {
764
+ applyPayload(part.text);
765
+ }
766
+ }
767
+ }
768
+
769
+ function applyApprovalMetadata(value) {
770
+ const metadata = value && typeof value === "object" ? value._meta : null;
771
+ if (
772
+ metadata &&
773
+ typeof metadata["${PLAN_APPROVAL_TOKEN_META_KEY}"] === "string"
774
+ ) {
775
+ approvalToken = metadata["${PLAN_APPROVAL_TOKEN_META_KEY}"];
776
+ }
777
+ }
778
+
779
+ function handleHostMessage(event) {
780
+ // App documents are opaque-origin, so the host window is the only
781
+ // identity available to authenticate a message against.
782
+ if (event.source !== window.parent) {
783
+ return;
784
+ }
785
+ const data = event.data;
786
+ if (!data || typeof data !== "object") {
787
+ return;
788
+ }
789
+ if (data.method === "ping") {
790
+ post({ jsonrpc: "2.0", id: data.id, result: {} });
791
+ return;
792
+ }
793
+ if (data.id != null && pending.has(data.id)) {
794
+ const waiter = pending.get(data.id);
795
+ pending.delete(data.id);
796
+ if (data.error) {
797
+ waiter.reject(data.error);
798
+ } else {
799
+ waiter.resolve(data.result);
800
+ }
801
+ return;
802
+ }
803
+ const method = data.method;
804
+ const params = data.params || {};
805
+ if (
806
+ method === "ui/notifications/tool-result" ||
807
+ method === "ui/tool-result" ||
808
+ method === "tools/call"
809
+ ) {
810
+ approvalToken = "";
811
+ applyApprovalMetadata(params);
812
+ applyApprovalMetadata(params.result);
813
+ applyContent(params.content || (params.result || {}).content || []);
814
+ if (params.structuredContent) {
815
+ applyPayload(params.structuredContent);
816
+ }
817
+ }
818
+ if (method === "ui/notifications/tool-input" && params.arguments) {
819
+ applyPayload(params.arguments);
820
+ }
821
+ if (method === "ui/notifications/host-context-changed") {
822
+ applyHostContext(params);
823
+ }
824
+ }
825
+
826
+ window.addEventListener("message", handleHostMessage);
827
+
828
+ element("approve").addEventListener("click", approve);
829
+ element("refine").addEventListener("click", () => {
830
+ refining = true;
831
+ element("approve").className = "button-secondary";
832
+ show("refineBox", true);
833
+ element("feedback").focus();
834
+ reportSize();
835
+ });
836
+ element("sendRefine").addEventListener("click", () => {
837
+ const feedback = (element("feedback").value || "").trim();
838
+ if (!feedback) {
839
+ return;
840
+ }
841
+ answer(
842
+ decision && decision.kind === "plan"
843
+ ? "Change the Superblocks plan: " + feedback
844
+ : feedback,
845
+ );
846
+ });
847
+
848
+ if (typeof ResizeObserver === "function") {
849
+ new ResizeObserver(reportSize).observe(document.documentElement);
850
+ }
851
+
852
+ void request("ui/initialize", {
853
+ appCapabilities: { availableDisplayModes: ["inline"] },
854
+ appInfo: { name: "gateway-decision", version: "0.0.1" },
855
+ protocolVersion: PROTOCOL_VERSION,
856
+ })
857
+ .then((result) => {
858
+ // Hosts hold back tool results until the app confirms it is ready.
859
+ notify("ui/notifications/initialized", {});
860
+ applyHostContext(result && result.hostContext);
861
+ if (result && result.toolResult) {
862
+ approvalToken = "";
863
+ applyApprovalMetadata(result.toolResult);
864
+ applyPayload(result.toolResult);
865
+ }
866
+ })
867
+ .catch(() => {
868
+ // Hosts that push tool results via notification still work.
869
+ })
870
+ .finally(reportSize);
871
+ })();
872
+ </script>
873
+ </body>
874
+ </html>
875
+ `;
876
+ //# sourceMappingURL=decision-card-html.js.map