@ambitresearch/genie 1.3.1

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 (301) hide show
  1. package/README.md +15 -0
  2. package/dist/auth/bearer.d.ts +49 -0
  3. package/dist/auth/bearer.d.ts.map +1 -0
  4. package/dist/auth/bearer.js +159 -0
  5. package/dist/auth/bearer.js.map +1 -0
  6. package/dist/auth/oauth/authorize.d.ts +19 -0
  7. package/dist/auth/oauth/authorize.d.ts.map +1 -0
  8. package/dist/auth/oauth/authorize.js +111 -0
  9. package/dist/auth/oauth/authorize.js.map +1 -0
  10. package/dist/auth/oauth/config.d.ts +10 -0
  11. package/dist/auth/oauth/config.d.ts.map +1 -0
  12. package/dist/auth/oauth/config.js +16 -0
  13. package/dist/auth/oauth/config.js.map +1 -0
  14. package/dist/auth/oauth/dcr.d.ts +15 -0
  15. package/dist/auth/oauth/dcr.d.ts.map +1 -0
  16. package/dist/auth/oauth/dcr.js +38 -0
  17. package/dist/auth/oauth/dcr.js.map +1 -0
  18. package/dist/auth/oauth/jwt.d.ts +13 -0
  19. package/dist/auth/oauth/jwt.d.ts.map +1 -0
  20. package/dist/auth/oauth/jwt.js +46 -0
  21. package/dist/auth/oauth/jwt.js.map +1 -0
  22. package/dist/auth/oauth/metadata.d.ts +9 -0
  23. package/dist/auth/oauth/metadata.d.ts.map +1 -0
  24. package/dist/auth/oauth/metadata.js +19 -0
  25. package/dist/auth/oauth/metadata.js.map +1 -0
  26. package/dist/auth/oauth/router.d.ts +32 -0
  27. package/dist/auth/oauth/router.d.ts.map +1 -0
  28. package/dist/auth/oauth/router.js +159 -0
  29. package/dist/auth/oauth/router.js.map +1 -0
  30. package/dist/auth/oauth/store.d.ts +55 -0
  31. package/dist/auth/oauth/store.d.ts.map +1 -0
  32. package/dist/auth/oauth/store.js +63 -0
  33. package/dist/auth/oauth/store.js.map +1 -0
  34. package/dist/auth/oauth/token.d.ts +21 -0
  35. package/dist/auth/oauth/token.d.ts.map +1 -0
  36. package/dist/auth/oauth/token.js +77 -0
  37. package/dist/auth/oauth/token.js.map +1 -0
  38. package/dist/auth/oidc/group-policy.d.ts +43 -0
  39. package/dist/auth/oidc/group-policy.d.ts.map +1 -0
  40. package/dist/auth/oidc/group-policy.js +54 -0
  41. package/dist/auth/oidc/group-policy.js.map +1 -0
  42. package/dist/auth/oidc/verifier.d.ts +42 -0
  43. package/dist/auth/oidc/verifier.d.ts.map +1 -0
  44. package/dist/auth/oidc/verifier.js +145 -0
  45. package/dist/auth/oidc/verifier.js.map +1 -0
  46. package/dist/auth/token-cli.d.ts +9 -0
  47. package/dist/auth/token-cli.d.ts.map +1 -0
  48. package/dist/auth/token-cli.js +98 -0
  49. package/dist/auth/token-cli.js.map +1 -0
  50. package/dist/cli.d.ts +3 -0
  51. package/dist/cli.d.ts.map +1 -0
  52. package/dist/cli.js +149 -0
  53. package/dist/cli.js.map +1 -0
  54. package/dist/config/redact.d.ts +20 -0
  55. package/dist/config/redact.d.ts.map +1 -0
  56. package/dist/config/redact.js +77 -0
  57. package/dist/config/redact.js.map +1 -0
  58. package/dist/config/secrets.d.ts +100 -0
  59. package/dist/config/secrets.d.ts.map +1 -0
  60. package/dist/config/secrets.js +130 -0
  61. package/dist/config/secrets.js.map +1 -0
  62. package/dist/framework/html.d.ts +103 -0
  63. package/dist/framework/html.d.ts.map +1 -0
  64. package/dist/framework/html.js +271 -0
  65. package/dist/framework/html.js.map +1 -0
  66. package/dist/framework/interface.d.ts +130 -0
  67. package/dist/framework/interface.d.ts.map +1 -0
  68. package/dist/framework/interface.js +112 -0
  69. package/dist/framework/interface.js.map +1 -0
  70. package/dist/framework/react.d.ts +133 -0
  71. package/dist/framework/react.d.ts.map +1 -0
  72. package/dist/framework/react.js +243 -0
  73. package/dist/framework/react.js.map +1 -0
  74. package/dist/framework/vue.d.ts +99 -0
  75. package/dist/framework/vue.d.ts.map +1 -0
  76. package/dist/framework/vue.js +375 -0
  77. package/dist/framework/vue.js.map +1 -0
  78. package/dist/index.d.ts +3 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +3 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/llm/client.d.ts +81 -0
  83. package/dist/llm/client.d.ts.map +1 -0
  84. package/dist/llm/client.js +141 -0
  85. package/dist/llm/client.js.map +1 -0
  86. package/dist/llm/component-response.d.ts +111 -0
  87. package/dist/llm/component-response.d.ts.map +1 -0
  88. package/dist/llm/component-response.js +167 -0
  89. package/dist/llm/component-response.js.map +1 -0
  90. package/dist/llm/generated-files.d.ts +10 -0
  91. package/dist/llm/generated-files.d.ts.map +1 -0
  92. package/dist/llm/generated-files.js +26 -0
  93. package/dist/llm/generated-files.js.map +1 -0
  94. package/dist/llm/prompts/CHANGELOG.md +70 -0
  95. package/dist/llm/prompts/generate-component.system.md +99 -0
  96. package/dist/llm/prompts/refine-component.system.md +112 -0
  97. package/dist/llm/prompts.d.ts +66 -0
  98. package/dist/llm/prompts.d.ts.map +1 -0
  99. package/dist/llm/prompts.js +78 -0
  100. package/dist/llm/prompts.js.map +1 -0
  101. package/dist/llm/retry.d.ts +183 -0
  102. package/dist/llm/retry.d.ts.map +1 -0
  103. package/dist/llm/retry.js +475 -0
  104. package/dist/llm/retry.js.map +1 -0
  105. package/dist/llm/schema.d.ts +129 -0
  106. package/dist/llm/schema.d.ts.map +1 -0
  107. package/dist/llm/schema.js +147 -0
  108. package/dist/llm/schema.js.map +1 -0
  109. package/dist/llm/validate.d.ts +107 -0
  110. package/dist/llm/validate.d.ts.map +1 -0
  111. package/dist/llm/validate.js +174 -0
  112. package/dist/llm/validate.js.map +1 -0
  113. package/dist/manifest/compiler.d.ts +112 -0
  114. package/dist/manifest/compiler.d.ts.map +1 -0
  115. package/dist/manifest/compiler.js +306 -0
  116. package/dist/manifest/compiler.js.map +1 -0
  117. package/dist/manifest/ensure.d.ts +46 -0
  118. package/dist/manifest/ensure.d.ts.map +1 -0
  119. package/dist/manifest/ensure.js +49 -0
  120. package/dist/manifest/ensure.js.map +1 -0
  121. package/dist/manifest/index.d.ts +13 -0
  122. package/dist/manifest/index.d.ts.map +1 -0
  123. package/dist/manifest/index.js +13 -0
  124. package/dist/manifest/index.js.map +1 -0
  125. package/dist/middleware/plan-guard.d.ts +167 -0
  126. package/dist/middleware/plan-guard.d.ts.map +1 -0
  127. package/dist/middleware/plan-guard.js +190 -0
  128. package/dist/middleware/plan-guard.js.map +1 -0
  129. package/dist/plans/index.d.ts +71 -0
  130. package/dist/plans/index.d.ts.map +1 -0
  131. package/dist/plans/index.js +252 -0
  132. package/dist/plans/index.js.map +1 -0
  133. package/dist/schemas/component.schema.json +114 -0
  134. package/dist/server.d.ts +96 -0
  135. package/dist/server.d.ts.map +1 -0
  136. package/dist/server.js +258 -0
  137. package/dist/server.js.map +1 -0
  138. package/dist/store/empty-manifest.d.ts +58 -0
  139. package/dist/store/empty-manifest.d.ts.map +1 -0
  140. package/dist/store/empty-manifest.js +59 -0
  141. package/dist/store/empty-manifest.js.map +1 -0
  142. package/dist/store/git-host.d.ts +120 -0
  143. package/dist/store/git-host.d.ts.map +1 -0
  144. package/dist/store/git-host.js +796 -0
  145. package/dist/store/git-host.js.map +1 -0
  146. package/dist/store/index.d.ts +5 -0
  147. package/dist/store/index.d.ts.map +1 -0
  148. package/dist/store/index.js +4 -0
  149. package/dist/store/index.js.map +1 -0
  150. package/dist/store/interface.d.ts +322 -0
  151. package/dist/store/interface.d.ts.map +1 -0
  152. package/dist/store/interface.js +100 -0
  153. package/dist/store/interface.js.map +1 -0
  154. package/dist/store/kit-files.d.ts +88 -0
  155. package/dist/store/kit-files.d.ts.map +1 -0
  156. package/dist/store/kit-files.js +199 -0
  157. package/dist/store/kit-files.js.map +1 -0
  158. package/dist/store/local.d.ts +70 -0
  159. package/dist/store/local.d.ts.map +1 -0
  160. package/dist/store/local.js +651 -0
  161. package/dist/store/local.js.map +1 -0
  162. package/dist/store/manifest.d.ts +44 -0
  163. package/dist/store/manifest.d.ts.map +1 -0
  164. package/dist/store/manifest.js +116 -0
  165. package/dist/store/manifest.js.map +1 -0
  166. package/dist/store/viewer-assets.d.ts +20 -0
  167. package/dist/store/viewer-assets.d.ts.map +1 -0
  168. package/dist/store/viewer-assets.js +118 -0
  169. package/dist/store/viewer-assets.js.map +1 -0
  170. package/dist/sync/anchor.d.ts +125 -0
  171. package/dist/sync/anchor.d.ts.map +1 -0
  172. package/dist/sync/anchor.js +210 -0
  173. package/dist/sync/anchor.js.map +1 -0
  174. package/dist/sync/index.d.ts +15 -0
  175. package/dist/sync/index.d.ts.map +1 -0
  176. package/dist/sync/index.js +15 -0
  177. package/dist/sync/index.js.map +1 -0
  178. package/dist/sync/orchestrator.d.ts +160 -0
  179. package/dist/sync/orchestrator.d.ts.map +1 -0
  180. package/dist/sync/orchestrator.js +288 -0
  181. package/dist/sync/orchestrator.js.map +1 -0
  182. package/dist/tools/bind_kit.d.ts +29 -0
  183. package/dist/tools/bind_kit.d.ts.map +1 -0
  184. package/dist/tools/bind_kit.js +70 -0
  185. package/dist/tools/bind_kit.js.map +1 -0
  186. package/dist/tools/conjure.d.ts +141 -0
  187. package/dist/tools/conjure.d.ts.map +1 -0
  188. package/dist/tools/conjure.js +655 -0
  189. package/dist/tools/conjure.js.map +1 -0
  190. package/dist/tools/conjure_screen.d.ts +174 -0
  191. package/dist/tools/conjure_screen.d.ts.map +1 -0
  192. package/dist/tools/conjure_screen.js +458 -0
  193. package/dist/tools/conjure_screen.js.map +1 -0
  194. package/dist/tools/create_kit.d.ts +32 -0
  195. package/dist/tools/create_kit.d.ts.map +1 -0
  196. package/dist/tools/create_kit.js +131 -0
  197. package/dist/tools/create_kit.js.map +1 -0
  198. package/dist/tools/create_project.d.ts +267 -0
  199. package/dist/tools/create_project.d.ts.map +1 -0
  200. package/dist/tools/create_project.js +546 -0
  201. package/dist/tools/create_project.js.map +1 -0
  202. package/dist/tools/delete_files.d.ts +93 -0
  203. package/dist/tools/delete_files.d.ts.map +1 -0
  204. package/dist/tools/delete_files.js +276 -0
  205. package/dist/tools/delete_files.js.map +1 -0
  206. package/dist/tools/delete_project.d.ts +43 -0
  207. package/dist/tools/delete_project.d.ts.map +1 -0
  208. package/dist/tools/delete_project.js +118 -0
  209. package/dist/tools/delete_project.js.map +1 -0
  210. package/dist/tools/get_kit.d.ts +28 -0
  211. package/dist/tools/get_kit.d.ts.map +1 -0
  212. package/dist/tools/get_kit.js +95 -0
  213. package/dist/tools/get_kit.js.map +1 -0
  214. package/dist/tools/get_project.d.ts +37 -0
  215. package/dist/tools/get_project.d.ts.map +1 -0
  216. package/dist/tools/get_project.js +71 -0
  217. package/dist/tools/get_project.js.map +1 -0
  218. package/dist/tools/list_components.d.ts +42 -0
  219. package/dist/tools/list_components.d.ts.map +1 -0
  220. package/dist/tools/list_components.js +125 -0
  221. package/dist/tools/list_components.js.map +1 -0
  222. package/dist/tools/list_files.d.ts +32 -0
  223. package/dist/tools/list_files.d.ts.map +1 -0
  224. package/dist/tools/list_files.js +109 -0
  225. package/dist/tools/list_files.js.map +1 -0
  226. package/dist/tools/list_kits.d.ts +14 -0
  227. package/dist/tools/list_kits.d.ts.map +1 -0
  228. package/dist/tools/list_kits.js +41 -0
  229. package/dist/tools/list_kits.js.map +1 -0
  230. package/dist/tools/list_projects.d.ts +23 -0
  231. package/dist/tools/list_projects.d.ts.map +1 -0
  232. package/dist/tools/list_projects.js +66 -0
  233. package/dist/tools/list_projects.js.map +1 -0
  234. package/dist/tools/plan.d.ts +16 -0
  235. package/dist/tools/plan.d.ts.map +1 -0
  236. package/dist/tools/plan.js +146 -0
  237. package/dist/tools/plan.js.map +1 -0
  238. package/dist/tools/preview.d.ts +289 -0
  239. package/dist/tools/preview.d.ts.map +1 -0
  240. package/dist/tools/preview.js +672 -0
  241. package/dist/tools/preview.js.map +1 -0
  242. package/dist/tools/read_file.d.ts +40 -0
  243. package/dist/tools/read_file.d.ts.map +1 -0
  244. package/dist/tools/read_file.js +114 -0
  245. package/dist/tools/read_file.js.map +1 -0
  246. package/dist/tools/refine.d.ts +220 -0
  247. package/dist/tools/refine.d.ts.map +1 -0
  248. package/dist/tools/refine.js +501 -0
  249. package/dist/tools/refine.js.map +1 -0
  250. package/dist/tools/validate.d.ts +74 -0
  251. package/dist/tools/validate.d.ts.map +1 -0
  252. package/dist/tools/validate.js +224 -0
  253. package/dist/tools/validate.js.map +1 -0
  254. package/dist/tools/write_files.d.ts +158 -0
  255. package/dist/tools/write_files.d.ts.map +1 -0
  256. package/dist/tools/write_files.js +541 -0
  257. package/dist/tools/write_files.js.map +1 -0
  258. package/dist/transport.d.ts +77 -0
  259. package/dist/transport.d.ts.map +1 -0
  260. package/dist/transport.js +448 -0
  261. package/dist/transport.js.map +1 -0
  262. package/dist/ui/card-asset-broker.d.ts +42 -0
  263. package/dist/ui/card-asset-broker.d.ts.map +1 -0
  264. package/dist/ui/card-asset-broker.js +479 -0
  265. package/dist/ui/card-asset-broker.js.map +1 -0
  266. package/dist/ui/grid-resource.d.ts +252 -0
  267. package/dist/ui/grid-resource.d.ts.map +1 -0
  268. package/dist/ui/grid-resource.js +680 -0
  269. package/dist/ui/grid-resource.js.map +1 -0
  270. package/dist/ui/viewer-static/index.html +95 -0
  271. package/dist/ui/viewer-static/viewer.css +451 -0
  272. package/dist/ui/viewer-static/viewer.js +1405 -0
  273. package/dist/validate/full-scan.d.ts +87 -0
  274. package/dist/validate/full-scan.d.ts.map +1 -0
  275. package/dist/validate/full-scan.js +299 -0
  276. package/dist/validate/full-scan.js.map +1 -0
  277. package/dist/validate/index.d.ts +15 -0
  278. package/dist/validate/index.d.ts.map +1 -0
  279. package/dist/validate/index.js +18 -0
  280. package/dist/validate/index.js.map +1 -0
  281. package/dist/validate/marker.d.ts +89 -0
  282. package/dist/validate/marker.d.ts.map +1 -0
  283. package/dist/validate/marker.js +87 -0
  284. package/dist/validate/marker.js.map +1 -0
  285. package/dist/validate/phash.d.ts +135 -0
  286. package/dist/validate/phash.d.ts.map +1 -0
  287. package/dist/validate/phash.js +307 -0
  288. package/dist/validate/phash.js.map +1 -0
  289. package/dist/validate/render.d.ts +38 -0
  290. package/dist/validate/render.d.ts.map +1 -0
  291. package/dist/validate/render.js +155 -0
  292. package/dist/validate/render.js.map +1 -0
  293. package/dist/watch/index.d.ts +12 -0
  294. package/dist/watch/index.d.ts.map +1 -0
  295. package/dist/watch/index.js +12 -0
  296. package/dist/watch/index.js.map +1 -0
  297. package/dist/watch/watcher.d.ts +65 -0
  298. package/dist/watch/watcher.d.ts.map +1 -0
  299. package/dist/watch/watcher.js +238 -0
  300. package/dist/watch/watcher.js.map +1 -0
  301. package/package.json +70 -0
@@ -0,0 +1,252 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { type Manifest, type ManifestCard } from "../manifest/index.js";
3
+ import type { CardAssetBroker, CardAssetKit } from "./card-asset-broker.js";
4
+ /**
5
+ * The embedded preview resource URI. `v` identifies the wire contract while
6
+ * the process-scoped nonce prevents hosts from reusing a stale app document
7
+ * after the MCP server restarts. It remains stable for every read in one
8
+ * process, so resource registration and tool metadata always agree.
9
+ */
10
+ export declare const GRID_RESOURCE_URI: string;
11
+ /** The spec-mandated MCP-Apps MIME (stable spec 2026-01-26; RFC §6.5). */
12
+ export declare const GRID_RESOURCE_MIME = "text/html;profile=mcp-app";
13
+ /** The DOM id `viewer.js` reads the inlined manifest from (must match it). */
14
+ export declare const MANIFEST_ELEMENT_ID = "manifest";
15
+ export declare const TOOL_RESULT_SHELL_META = "genie-tool-result-shell";
16
+ /** Legacy sibling asset URIs retained for older experimental hosts. */
17
+ export declare const VIEWER_JS_URI = "ui://genie/viewer.js";
18
+ export declare const VIEWER_CSS_URI = "ui://genie/viewer.css";
19
+ /** Compiles the on-disk kit at `kitDir` to a manifest (default: M3-03). */
20
+ export type ManifestCompiler = (kitDir: string) => Promise<Manifest>;
21
+ /** The three static assets the embedded shell is assembled from. */
22
+ export type ViewerAssetName = "index.html" | "viewer.js" | "viewer.css";
23
+ /** Reads one `@ambitresearch/genie-viewer` static asset's text (default: from disk). */
24
+ export type AssetReader = (name: ViewerAssetName) => Promise<string>;
25
+ /** Reads a preview file's raw bytes for the `data:` fallback, or null. */
26
+ export type PreviewReader = (kitDir: string, relPath: string) => Promise<Buffer | null>;
27
+ /** Embedded transport card: stable kit identity plus its vehicle-specific URL. */
28
+ export interface EmbeddedManifestCard extends ManifestCard {
29
+ sourcePath: string;
30
+ }
31
+ /** Manifest shape inlined into the embedded viewer document. */
32
+ export interface EmbeddedManifest extends Omit<Manifest, "components"> {
33
+ components: EmbeddedManifestCard[];
34
+ }
35
+ /** Exact CSP hashes for trusted inline executable/style blocks. */
36
+ export interface InlineCspHashes {
37
+ scriptHashes: string[];
38
+ styleHashes: string[];
39
+ }
40
+ /** Options for {@link registerGridResource}. Every collaborator is injectable. */
41
+ export interface GridResourceOptions {
42
+ /** Kits root — the same value the kit verbs + `preview` resolve against. */
43
+ kitsRoot: string;
44
+ /** Manifest compiler seam (default wraps M3-03 `compileManifest`). */
45
+ compile?: ManifestCompiler;
46
+ /** Static-asset reader seam (default reads `@ambitresearch/genie-viewer/static`). */
47
+ readAsset?: AssetReader;
48
+ /** Preview-bytes reader for the `data:` fallback (default reads from disk). */
49
+ readPreviewBytes?: PreviewReader;
50
+ /**
51
+ * Separate-origin previews host base URL for AC4 (e.g.
52
+ * `https://previews.example.com`). When set, each card iframe `src` becomes
53
+ * `${base}/${kitId}/${card.path}`. When absent (solo dev), the handler falls
54
+ * back to a `data:text/html;base64,…` inline URL built from the preview's
55
+ * bytes. Defaults to `process.env.GENIE_PREVIEWS_BASE_URL`.
56
+ */
57
+ previewsBaseUrl?: string;
58
+ /**
59
+ * Lazily resolves the process-scoped local card broker used by UI-capable
60
+ * hosts. Omit this seam for legacy/unit callers that require the self-
61
+ * contained `data:` fallback.
62
+ */
63
+ getCardAssetBroker?: () => Promise<CardAssetBroker>;
64
+ }
65
+ /**
66
+ * Resolve `kitId` to its on-disk dir under `kitsRoot`, or `null` when the id is
67
+ * absent or fails {@link KIT_ID_PATTERN}. Returning `null` (rather than
68
+ * throwing) lets the handler degrade to an EMPTY grid instead of erroring a
69
+ * host's `resources/read` — a hostile or malformed `kitId` can never escape the
70
+ * kits root (RFC §10 T-13, the same guard `preview`/`read_file` apply).
71
+ */
72
+ export declare function resolveKitDir(kitsRoot: string, kitId: string | undefined): string | null;
73
+ /**
74
+ * Narrow a manifest to an optional single component and/or group (the
75
+ * `componentName` / `group` query params `preview` forwards). Exact,
76
+ * case-sensitive matches — the fuzzy substring search is the viewer's job
77
+ * (`#q`); this pre-filter is deterministic so the inlined payload is stable for
78
+ * a given URI. `groups` is recomputed from what survives so no empty section is
79
+ * inlined. A filter that matches nothing yields an empty-but-valid manifest
80
+ * (the viewer renders its empty state).
81
+ */
82
+ export declare function filterManifest(manifest: Manifest, filter: {
83
+ componentName?: string;
84
+ group?: string;
85
+ }): Manifest;
86
+ /**
87
+ * Validate + normalise a configured previews base URL. Returns the parsed
88
+ * `URL` (its `href` forced to end in `/` so a later relative-join appends
89
+ * rather than replacing the last path segment) when `raw` is a well-formed
90
+ * ABSOLUTE `http(s)` URL, else `undefined`. A malformed value (a bare host, a
91
+ * typo, a non-http scheme) degrades to `undefined` — the caller then falls
92
+ * back to the solo-dev `data:` transport instead of throwing. Centralising the
93
+ * one `new URL()` parse here is what keeps `rewriteCardPaths` /`buildCspMeta`
94
+ * from crashing `resources/read` or server startup on bad config (the exact
95
+ * failure the reviewer flagged): validate once, branch on the result.
96
+ */
97
+ export declare function normalizePreviewsBaseUrl(raw: string | undefined): URL | undefined;
98
+ /**
99
+ * Preserve every card's kit-relative identity as `sourcePath`, then rewrite
100
+ * `path` to the URL the EMBEDDED tier's iframe should load (AC4). With a valid
101
+ * `previewsBaseUrl`, that's an absolute `https://` URL on
102
+ * the separate previews origin (`${base}/${kitId}/${path}`) — the cross-origin
103
+ * isolation the RFC §6/T-09 recommends. Without one — OR when the configured
104
+ * base URL is malformed (see {@link normalizePreviewsBaseUrl}) — the preview's
105
+ * bytes are read and encoded as a `data:text/html;base64,…` URL so the grid is
106
+ * fully self-contained. A preview whose bytes can't be read keeps its relative
107
+ * `path` (harmless: that card simply won't resolve in the embedded tier — a
108
+ * strictly better degradation than dropping the card).
109
+ *
110
+ * Card CONTENT is never altered here — only the URL the iframe points at — so
111
+ * the card stays byte-identical to the `file://`/localhost vehicles (G-5).
112
+ */
113
+ export declare function rewriteCardPaths(manifest: Manifest, opts: {
114
+ kitId: string;
115
+ kitDir: string;
116
+ previewsBaseUrl?: string;
117
+ readPreviewBytes: PreviewReader;
118
+ cardAssetKit?: CardAssetKit;
119
+ onPreviewHtml?: (html: string) => void;
120
+ }): Promise<EmbeddedManifest>;
121
+ /**
122
+ * Escape a JSON string for safe embedding inside `<script type="application/
123
+ * json">`. In JSON, `<`/`>`/`&` only ever occur INSIDE string literals, so
124
+ * replacing them with their `\uXXXX` escapes yields equivalent, still-valid
125
+ * JSON that no HTML parser can misread as a `</script>` terminator or a comment
126
+ * (`<!--`). U+2028/U+2029 are escaped too (defensive; they're legal in JSON but
127
+ * not in JS string literals, and some embedders re-parse). This is the
128
+ * canonical safe-embedding transform.
129
+ */
130
+ export declare function escapeJsonForScript(json: string): string;
131
+ /**
132
+ * Inject the compiled manifest into the viewer's `index.html` as an inline
133
+ * `<script type="application/json" id="manifest">` (AC2), placed just before
134
+ * `</head>` so it parses before `viewer.js` runs. If no `</head>` is present
135
+ * (defensive — the shipped shell always has one) the script is prepended, which
136
+ * still parses before the body script. The manifest is JSON-escaped so a
137
+ * hostile component name/path can't break out of the script element.
138
+ */
139
+ export declare function inlineManifest(indexHtml: string, manifest: Manifest): string;
140
+ /**
141
+ * Parse HTML and hash its trusted inline `<script>` / `<style>` text exactly as
142
+ * the browser sees it. External scripts have no inline bytes and are ignored.
143
+ */
144
+ export declare function collectInlineCspHashes(html: string): InlineCspHashes;
145
+ /**
146
+ * Make the MCP App document self-contained. A host receives one raw HTML
147
+ * resource; browser-relative `ui://` siblings are not additional resources/read
148
+ * calls, so the exact viewer JS/CSS bytes must travel inside that document.
149
+ */
150
+ export declare function inlineViewerAssets(indexHtml: string, viewerJs: string, viewerCss: string): {
151
+ html: string;
152
+ hashes: InlineCspHashes;
153
+ };
154
+ /**
155
+ * MCP Apps domain declarations plus genie's stricter in-document CSP.
156
+ * Resources/read cannot deliver an HTTP response header; compliant hosts build
157
+ * their sandbox CSP from the domain arrays under `_meta.ui.csp`.
158
+ */
159
+ export interface GridCspMeta {
160
+ /** `fetch()`/XHR targets — empty: the manifest is inlined, nothing to fetch. */
161
+ connectDomains: string[];
162
+ /** External static-resource origins; empty because the document is self-contained. */
163
+ resourceDomains: string[];
164
+ /** Origins allowed as per-card iframe sources (the previews host or `data:`). */
165
+ frameDomains: string[];
166
+ /** Strict hash-based policy injected into the self-contained HTML document. */
167
+ metaPolicy: string;
168
+ }
169
+ /**
170
+ * Build the AC5 domain allow-list and strict hash-based document policy.
171
+ *
172
+ * The card iframes load from the previews origin when configured, else from
173
+ * `data:` (solo dev). `connectDomains` is always empty — `connect-src 'none'`
174
+ * — because the manifest travels inline (AC2); there is nothing to fetch.
175
+ * `img-src` permits `data:`/`https:` for card thumbnails. The domain shape
176
+ * matches the stable MCP Apps 2026-01-26 `_meta.ui.csp` contract.
177
+ *
178
+ * Hardening applied vs the pre-M4-07 policy:
179
+ * • Removed `'unsafe-inline'` / `'unsafe-eval'` (AC3). The exact inlined
180
+ * viewer assets and legitimate inline blocks inside data-backed cards are
181
+ * allow-listed by SHA-256. Event-handler attributes remain blocked because
182
+ * the policy does not opt into `'unsafe-hashes'`.
183
+ * • Added `base-uri 'none'` — no `<base href>` can redirect URLs.
184
+ * • Added `form-action 'none'` and `object-src 'none'` — deny `<form>` /
185
+ * `<object>` / `<embed>` per AC1's "deny form/object/embed" line.
186
+ * Resources/read has no HTTP-header channel, so no raw header policy or
187
+ * `frame-ancestors` claim is advertised.
188
+ */
189
+ export declare function buildCspMeta(previewsBaseUrl: string | undefined, inlineHashes?: InlineCspHashes, exactFrameDomains?: readonly string[]): GridCspMeta;
190
+ /**
191
+ * Render a `<meta http-equiv="Content-Security-Policy" content="…">` tag for
192
+ * the given policy meta. Uses {@link GridCspMeta.metaPolicy}.
193
+ *
194
+ * The `content` attribute value is HTML-attribute-escaped (`&`, `"`, `<`, `>`)
195
+ * defensively. In current use the policy string is server-authored with no
196
+ * user input, so the escape is defence-in-depth against a future change that
197
+ * accidentally embeds a `"` — without it the attribute would terminate early
198
+ * and the policy would silently degrade.
199
+ */
200
+ export declare function cspMetaTag(meta: GridCspMeta): string;
201
+ /**
202
+ * Inject the enforced CSP meta into an assembled document. Placed at the very
203
+ * top of `<head>` so every subsequent element — the manifest data island,
204
+ * inlined `viewer.js`/`viewer.css`, any inline attributes — is parsed under
205
+ * the policy. If the shell has no `<head>` (defensive; every shipped shell
206
+ * does) the tag is prepended so it still parses first.
207
+ */
208
+ export declare function injectCspMeta(html: string, meta: GridCspMeta): string;
209
+ /** Canonical MCP Apps resource metadata (stable 2026-01-26 shape). */
210
+ export declare function gridResourceMeta(previewsBaseUrl: string | undefined, exactFrameDomains?: readonly string[]): Record<string, unknown>;
211
+ /** Fully-resolved dependencies for {@link buildGridDocument}. */
212
+ interface ResolvedDeps {
213
+ kitsRoot: string;
214
+ compile: ManifestCompiler;
215
+ readAsset: AssetReader;
216
+ readPreviewBytes: PreviewReader;
217
+ previewsBaseUrl: string | undefined;
218
+ getCardAssetBroker?: () => Promise<CardAssetBroker>;
219
+ cardAssetKit?: CardAssetKit;
220
+ exactFrameDomains?: readonly string[];
221
+ denyRequestedKit?: boolean;
222
+ }
223
+ /**
224
+ * Produce the embedded grid HTML for a resource URI's query params. Resolves
225
+ * the kit (path-guarded), compiles + filters the manifest, rewrites card paths
226
+ * for the embedded tier (AC4), inlines the result into the viewer shell
227
+ * (AC2/AC3), and injects the enforced CSP meta (M4-07 AC1) so browsers apply
228
+ * the hardened policy at parse time. Every failure mode degrades to a still-
229
+ * valid, still-hardened document: an absent/invalid `kitId` or an
230
+ * uncompilable kit yields an EMPTY manifest (the viewer's empty state);
231
+ * unreadable viewer assets yield the {@link fallbackShell} (also CSP-injected).
232
+ */
233
+ export declare function buildGridDocument(deps: ResolvedDeps, params: {
234
+ kitId?: string;
235
+ componentName?: string;
236
+ group?: string;
237
+ }): Promise<string>;
238
+ /**
239
+ * Register `ui://genie/grid` and its sibling assets on `server`.
240
+ *
241
+ * Routing (verified against the installed SDK): the SDK matches a static
242
+ * resource by EXACT `uri.toString()` and a template via `UriTemplate.match`.
243
+ * `preview` emits `ui://genie/grid?kitId=…` with optional extra params, so a
244
+ * single static registration (no query) or a rigid `{?kitId,…}` template (all-
245
+ * or-nothing) would miss most real URIs. We therefore register BOTH a static
246
+ * `ui://genie/grid` (the bare URI) and a `{+rest}` catch-all template that
247
+ * matches any query-bearing URI; both dispatch to the same handler, which reads
248
+ * its params off the full `URL`. Legacy sibling assets remain plain statics.
249
+ */
250
+ export declare function registerGridResource(server: McpServer, options: GridResourceOptions): void;
251
+ export {};
252
+ //# sourceMappingURL=grid-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-resource.d.ts","sourceRoot":"","sources":["../../src/ui/grid-resource.ts"],"names":[],"mappings":"AAmDA,OAAO,EAAE,SAAS,EAAoB,MAAM,yCAAyC,CAAC;AAItF,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAExF,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAI5E;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,QAAoE,CAAC;AAEnG,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,eAAO,MAAM,sBAAsB,4BAA4B,CAAC;AAEhE,uEAAuE;AACvE,eAAO,MAAM,aAAa,yBAAyB,CAAC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