@toon-protocol/views 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/a2ui/A2UIRenderer.d.ts +47 -0
  2. package/dist/a2ui/A2UIRenderer.d.ts.map +1 -0
  3. package/dist/a2ui/A2UIRenderer.js +106 -0
  4. package/dist/a2ui/A2UIRenderer.js.map +1 -0
  5. package/dist/a2ui/binding.d.ts +46 -0
  6. package/dist/a2ui/binding.d.ts.map +1 -0
  7. package/dist/a2ui/binding.js +111 -0
  8. package/dist/a2ui/binding.js.map +1 -0
  9. package/dist/a2ui/index.d.ts +17 -0
  10. package/dist/a2ui/index.d.ts.map +1 -0
  11. package/dist/a2ui/index.js +17 -0
  12. package/dist/a2ui/index.js.map +1 -0
  13. package/dist/a2ui/types.d.ts +101 -0
  14. package/dist/a2ui/types.d.ts.map +1 -0
  15. package/dist/a2ui/types.js +64 -0
  16. package/dist/a2ui/types.js.map +1 -0
  17. package/dist/a2ui/validate.d.ts +55 -0
  18. package/dist/a2ui/validate.d.ts.map +1 -0
  19. package/dist/a2ui/validate.js +117 -0
  20. package/dist/a2ui/validate.js.map +1 -0
  21. package/dist/app/index.html +246 -0
  22. package/dist/app-bridge/ext-apps-bridge.d.ts +16 -0
  23. package/dist/app-bridge/ext-apps-bridge.d.ts.map +1 -0
  24. package/dist/app-bridge/ext-apps-bridge.js +66 -0
  25. package/dist/app-bridge/ext-apps-bridge.js.map +1 -0
  26. package/dist/app-bridge/types.d.ts +41 -0
  27. package/dist/app-bridge/types.d.ts.map +1 -0
  28. package/dist/app-bridge/types.js +10 -0
  29. package/dist/app-bridge/types.js.map +1 -0
  30. package/dist/app-entry.d.ts +13 -0
  31. package/dist/app-entry.d.ts.map +1 -0
  32. package/dist/app-entry.js +45 -0
  33. package/dist/app-entry.js.map +1 -0
  34. package/dist/atoms/defi.d.ts +3 -0
  35. package/dist/atoms/defi.d.ts.map +1 -0
  36. package/dist/atoms/defi.js +80 -0
  37. package/dist/atoms/defi.js.map +1 -0
  38. package/dist/atoms/fallback.d.ts +4 -0
  39. package/dist/atoms/fallback.d.ts.map +1 -0
  40. package/dist/atoms/fallback.js +15 -0
  41. package/dist/atoms/fallback.js.map +1 -0
  42. package/dist/atoms/forge.d.ts +3 -0
  43. package/dist/atoms/forge.d.ts.map +1 -0
  44. package/dist/atoms/forge.js +50 -0
  45. package/dist/atoms/forge.js.map +1 -0
  46. package/dist/atoms/interactive.d.ts +3 -0
  47. package/dist/atoms/interactive.d.ts.map +1 -0
  48. package/dist/atoms/interactive.js +99 -0
  49. package/dist/atoms/interactive.js.map +1 -0
  50. package/dist/atoms/layout.d.ts +3 -0
  51. package/dist/atoms/layout.d.ts.map +1 -0
  52. package/dist/atoms/layout.js +22 -0
  53. package/dist/atoms/layout.js.map +1 -0
  54. package/dist/atoms/media.d.ts +3 -0
  55. package/dist/atoms/media.d.ts.map +1 -0
  56. package/dist/atoms/media.js +92 -0
  57. package/dist/atoms/media.js.map +1 -0
  58. package/dist/atoms/onboard.d.ts +3 -0
  59. package/dist/atoms/onboard.d.ts.map +1 -0
  60. package/dist/atoms/onboard.js +26 -0
  61. package/dist/atoms/onboard.js.map +1 -0
  62. package/dist/atoms/registry.d.ts +35 -0
  63. package/dist/atoms/registry.d.ts.map +1 -0
  64. package/dist/atoms/registry.js +77 -0
  65. package/dist/atoms/registry.js.map +1 -0
  66. package/dist/atoms/social.d.ts +3 -0
  67. package/dist/atoms/social.d.ts.map +1 -0
  68. package/dist/atoms/social.js +52 -0
  69. package/dist/atoms/social.js.map +1 -0
  70. package/dist/atoms/types.d.ts +72 -0
  71. package/dist/atoms/types.d.ts.map +1 -0
  72. package/dist/atoms/types.js +11 -0
  73. package/dist/atoms/types.js.map +1 -0
  74. package/dist/catalog.d.ts +27 -0
  75. package/dist/catalog.d.ts.map +1 -0
  76. package/dist/catalog.js +121 -0
  77. package/dist/catalog.js.map +1 -0
  78. package/dist/components/mono-id.d.ts +16 -0
  79. package/dist/components/mono-id.d.ts.map +1 -0
  80. package/dist/components/mono-id.js +18 -0
  81. package/dist/components/mono-id.js.map +1 -0
  82. package/dist/components/ui/avatar.d.ts +12 -0
  83. package/dist/components/ui/avatar.d.ts.map +1 -0
  84. package/dist/components/ui/avatar.js +25 -0
  85. package/dist/components/ui/avatar.js.map +1 -0
  86. package/dist/components/ui/badge.d.ts +10 -0
  87. package/dist/components/ui/badge.d.ts.map +1 -0
  88. package/dist/components/ui/badge.js +26 -0
  89. package/dist/components/ui/badge.js.map +1 -0
  90. package/dist/components/ui/button.d.ts +11 -0
  91. package/dist/components/ui/button.d.ts.map +1 -0
  92. package/dist/components/ui/button.js +37 -0
  93. package/dist/components/ui/button.js.map +1 -0
  94. package/dist/components/ui/input.d.ts +4 -0
  95. package/dist/components/ui/input.d.ts.map +1 -0
  96. package/dist/components/ui/input.js +8 -0
  97. package/dist/components/ui/input.js.map +1 -0
  98. package/dist/components/ui/separator.d.ts +5 -0
  99. package/dist/components/ui/separator.d.ts.map +1 -0
  100. package/dist/components/ui/separator.js +9 -0
  101. package/dist/components/ui/separator.js.map +1 -0
  102. package/dist/components/ui/textarea.d.ts +4 -0
  103. package/dist/components/ui/textarea.d.ts.map +1 -0
  104. package/dist/components/ui/textarea.js +8 -0
  105. package/dist/components/ui/textarea.js.map +1 -0
  106. package/dist/examples.d.ts +39 -0
  107. package/dist/examples.d.ts.map +1 -0
  108. package/dist/examples.js +168 -0
  109. package/dist/examples.js.map +1 -0
  110. package/dist/filters.d.ts +40 -0
  111. package/dist/filters.d.ts.map +1 -0
  112. package/dist/filters.js +84 -0
  113. package/dist/filters.js.map +1 -0
  114. package/dist/index.d.ts +18 -0
  115. package/dist/index.d.ts.map +1 -0
  116. package/dist/index.js +18 -0
  117. package/dist/index.js.map +1 -0
  118. package/dist/lib/cn.d.ts +4 -0
  119. package/dist/lib/cn.d.ts.map +1 -0
  120. package/dist/lib/cn.js +7 -0
  121. package/dist/lib/cn.js.map +1 -0
  122. package/dist/lib/utils.d.ts +3 -0
  123. package/dist/lib/utils.d.ts.map +1 -0
  124. package/dist/lib/utils.js +6 -0
  125. package/dist/lib/utils.js.map +1 -0
  126. package/dist/main.d.ts +3 -0
  127. package/dist/main.d.ts.map +1 -0
  128. package/dist/main.js +7 -0
  129. package/dist/main.js.map +1 -0
  130. package/dist/mcp-ui/ConsentPrompt.d.ts +41 -0
  131. package/dist/mcp-ui/ConsentPrompt.d.ts.map +1 -0
  132. package/dist/mcp-ui/ConsentPrompt.js +45 -0
  133. package/dist/mcp-ui/ConsentPrompt.js.map +1 -0
  134. package/dist/mcp-ui/SandboxedAppRenderer.d.ts +54 -0
  135. package/dist/mcp-ui/SandboxedAppRenderer.d.ts.map +1 -0
  136. package/dist/mcp-ui/SandboxedAppRenderer.js +74 -0
  137. package/dist/mcp-ui/SandboxedAppRenderer.js.map +1 -0
  138. package/dist/mcp-ui/index.d.ts +18 -0
  139. package/dist/mcp-ui/index.d.ts.map +1 -0
  140. package/dist/mcp-ui/index.js +18 -0
  141. package/dist/mcp-ui/index.js.map +1 -0
  142. package/dist/mcp-ui/sandbox.d.ts +62 -0
  143. package/dist/mcp-ui/sandbox.d.ts.map +1 -0
  144. package/dist/mcp-ui/sandbox.js +78 -0
  145. package/dist/mcp-ui/sandbox.js.map +1 -0
  146. package/dist/parsers/media.d.ts +68 -0
  147. package/dist/parsers/media.d.ts.map +1 -0
  148. package/dist/parsers/media.js +124 -0
  149. package/dist/parsers/media.js.map +1 -0
  150. package/dist/parsers/nip34.d.ts +75 -0
  151. package/dist/parsers/nip34.d.ts.map +1 -0
  152. package/dist/parsers/nip34.js +142 -0
  153. package/dist/parsers/nip34.js.map +1 -0
  154. package/dist/parsers/social.d.ts +89 -0
  155. package/dist/parsers/social.d.ts.map +1 -0
  156. package/dist/parsers/social.js +136 -0
  157. package/dist/parsers/social.js.map +1 -0
  158. package/dist/render/node-shims/node-builtins.d.ts +30 -0
  159. package/dist/render/node-shims/node-builtins.d.ts.map +1 -0
  160. package/dist/render/node-shims/node-builtins.js +38 -0
  161. package/dist/render/node-shims/node-builtins.js.map +1 -0
  162. package/dist/render/resolve.d.ts +72 -0
  163. package/dist/render/resolve.d.ts.map +1 -0
  164. package/dist/render/resolve.js +115 -0
  165. package/dist/render/resolve.js.map +1 -0
  166. package/dist/runtime.d.ts +17 -0
  167. package/dist/runtime.d.ts.map +1 -0
  168. package/dist/runtime.js +218 -0
  169. package/dist/runtime.js.map +1 -0
  170. package/dist/server/apps-server.d.ts +32 -0
  171. package/dist/server/apps-server.d.ts.map +1 -0
  172. package/dist/server/apps-server.js +163 -0
  173. package/dist/server/apps-server.js.map +1 -0
  174. package/dist/server/backend.d.ts +148 -0
  175. package/dist/server/backend.d.ts.map +1 -0
  176. package/dist/server/backend.js +11 -0
  177. package/dist/server/backend.js.map +1 -0
  178. package/dist/server/daemon-backend.d.ts +113 -0
  179. package/dist/server/daemon-backend.d.ts.map +1 -0
  180. package/dist/server/daemon-backend.js +79 -0
  181. package/dist/server/daemon-backend.js.map +1 -0
  182. package/dist/server/daemon-main.d.ts +25 -0
  183. package/dist/server/daemon-main.d.ts.map +1 -0
  184. package/dist/server/daemon-main.js +165 -0
  185. package/dist/server/daemon-main.js.map +1 -0
  186. package/dist/server/fake-backend.d.ts +53 -0
  187. package/dist/server/fake-backend.d.ts.map +1 -0
  188. package/dist/server/fake-backend.js +157 -0
  189. package/dist/server/fake-backend.js.map +1 -0
  190. package/dist/server/fake-main.d.ts +15 -0
  191. package/dist/server/fake-main.d.ts.map +1 -0
  192. package/dist/server/fake-main.js +39 -0
  193. package/dist/server/fake-main.js.map +1 -0
  194. package/dist/spec.d.ts +67 -0
  195. package/dist/spec.d.ts.map +1 -0
  196. package/dist/spec.js +221 -0
  197. package/dist/spec.js.map +1 -0
  198. package/dist/tool-names.d.ts +27 -0
  199. package/dist/tool-names.d.ts.map +1 -0
  200. package/dist/tool-names.js +32 -0
  201. package/dist/tool-names.js.map +1 -0
  202. package/dist/types.d.ts +39 -0
  203. package/dist/types.d.ts.map +1 -0
  204. package/dist/types.js +20 -0
  205. package/dist/types.js.map +1 -0
  206. package/package.json +71 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A2UIRenderer — branch 2 of the NIP-on-TOON render trust gradient (medium
3
+ * trust). Renders an A2UI `surfaceUpdate` template, bound to a decoded TOON
4
+ * event as the `dataModelUpdate`, using the client's OWN audited component
5
+ * primitives — never provider code. See toon-meta#58, toon-client#89.
6
+ *
7
+ * Binding convention (spec §"Branch 2"):
8
+ * - the `kind:31036` renderer `content` = the A2UI `surfaceUpdate` (template),
9
+ * - the decoded event = the `dataModelUpdate` (data), and
10
+ * - the `["a2ui", "<version>"]` tag selects the renderer version.
11
+ *
12
+ * Standard-catalog-only invariant: only the A2UI "Basic" catalog is rendered
13
+ * here. {@link validateA2uiRenderer} is the gate; a custom component or custom
14
+ * behavior REFUSES and signals a drop to branch 3 (sandboxed mcp-ui) — this
15
+ * component never renders a refused surface, it renders nothing and reports the
16
+ * fallback via {@link A2UIRendererProps.onFallback}.
17
+ */
18
+ import { type FC } from 'react';
19
+ import { type NostrEvent } from '../types.js';
20
+ import { type A2uiGateRefuse } from './validate.js';
21
+ /** Inputs to {@link A2UIRenderer}, mirroring the branch-2 dispatch decision. */
22
+ export interface A2UIRendererProps {
23
+ /**
24
+ * The resolved `kind:31036` renderer event — its `content` is the A2UI
25
+ * `surfaceUpdate` template and its `tags` carry the `["a2ui", …]` version.
26
+ * (The `A2uiDecision.renderer` from `@toon-protocol/client`'s `renderDispatch`.)
27
+ */
28
+ renderer: NostrEvent;
29
+ /**
30
+ * The decoded TOON event fed in as the `dataModelUpdate` root. (The
31
+ * `A2uiDecision.event` — already decoded via `core.decodeEventFromToon`.)
32
+ */
33
+ event: NostrEvent;
34
+ /**
35
+ * Called when the standard-catalog-only gate REFUSES the surface, signalling
36
+ * the host to drop to another branch (`'mcp-ui'` = branch 3, `'native'` =
37
+ * fall through to branch 1/4). The renderer itself renders nothing in this
38
+ * case — the host owns the fallback render.
39
+ */
40
+ onFallback?: (refusal: A2uiGateRefuse) => void;
41
+ }
42
+ /**
43
+ * Branch 2 entry point. Runs the standard-catalog-only gate, then renders the
44
+ * surface at medium trust — or signals a fallback and renders nothing.
45
+ */
46
+ export declare const A2UIRenderer: FC<A2UIRendererProps>;
47
+ //# sourceMappingURL=A2UIRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2UIRenderer.d.ts","sourceRoot":"","sources":["../../src/a2ui/A2UIRenderer.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAW,KAAK,EAAE,EAAkB,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAM9C,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAG1E,gFAAgF;AAChF,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,EAAE,UAAU,CAAC;IACrB;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CAChD;AAuGD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAc9C,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * A2UIRenderer — branch 2 of the NIP-on-TOON render trust gradient (medium
4
+ * trust). Renders an A2UI `surfaceUpdate` template, bound to a decoded TOON
5
+ * event as the `dataModelUpdate`, using the client's OWN audited component
6
+ * primitives — never provider code. See toon-meta#58, toon-client#89.
7
+ *
8
+ * Binding convention (spec §"Branch 2"):
9
+ * - the `kind:31036` renderer `content` = the A2UI `surfaceUpdate` (template),
10
+ * - the decoded event = the `dataModelUpdate` (data), and
11
+ * - the `["a2ui", "<version>"]` tag selects the renderer version.
12
+ *
13
+ * Standard-catalog-only invariant: only the A2UI "Basic" catalog is rendered
14
+ * here. {@link validateA2uiRenderer} is the gate; a custom component or custom
15
+ * behavior REFUSES and signals a drop to branch 3 (sandboxed mcp-ui) — this
16
+ * component never renders a refused surface, it renders nothing and reports the
17
+ * fallback via {@link A2UIRendererProps.onFallback}.
18
+ */
19
+ import { useMemo } from 'react';
20
+ import { Separator } from '@/components/ui/separator.js';
21
+ import { cn } from '@/lib/utils.js';
22
+ import {} from '../types.js';
23
+ import {} from './types.js';
24
+ import { validateA2uiRenderer } from './validate.js';
25
+ import { dataModelFromEvent, resolveText, stringProp } from './binding.js';
26
+ /** Resolve a node's children to component nodes, preserving order. */
27
+ function childNodes(node, byId) {
28
+ if (!Array.isArray(node.children))
29
+ return [];
30
+ return node.children
31
+ .map((id) => byId.get(id))
32
+ .filter((n) => n !== undefined);
33
+ }
34
+ /** Render one Basic-catalog node and its subtree. Pure — no behavior executed. */
35
+ function renderNode(node, byId, model, seen) {
36
+ // Cycle guard — a malformed template must never recurse forever.
37
+ if (seen.has(node.id))
38
+ return null;
39
+ seen.add(node.id);
40
+ const kids = childNodes(node, byId).map((child) => (_jsx(RenderChild, { node: child, byId: byId, model: model, seen: seen }, child.id)));
41
+ switch (node.component) {
42
+ case 'Text': {
43
+ const text = resolveText(node['text'], model);
44
+ return _jsx("p", { className: "text-sm leading-relaxed whitespace-pre-wrap break-words", children: text });
45
+ }
46
+ case 'Heading': {
47
+ const text = resolveText(node['text'] ?? node['title'], model);
48
+ return _jsx("h3", { className: "text-base font-semibold leading-tight", children: text });
49
+ }
50
+ case 'Image': {
51
+ const src = stringProp(node, 'src', model) ?? stringProp(node, 'url', model);
52
+ const alt = stringProp(node, 'alt', model) ?? '';
53
+ if (!src)
54
+ return null;
55
+ return _jsx("img", { src: src, alt: alt, className: "max-w-full rounded-md" });
56
+ }
57
+ case 'Icon': {
58
+ // Render the icon name as a label; we do not load arbitrary icon code.
59
+ const name = stringProp(node, 'name', model) ?? stringProp(node, 'icon', model) ?? '';
60
+ return _jsx("span", { "aria-hidden": true, className: "text-muted-foreground text-xs", children: name });
61
+ }
62
+ case 'Divider':
63
+ return _jsx(Separator, { className: "my-2" });
64
+ case 'Row':
65
+ return _jsx("div", { className: "flex flex-row flex-wrap items-start gap-3", children: kids });
66
+ case 'Column':
67
+ return _jsx("div", { className: "flex flex-col gap-2", children: kids });
68
+ case 'List':
69
+ return _jsx("div", { className: "flex flex-col divide-y divide-border", children: kids });
70
+ case 'Card':
71
+ return (_jsx("div", { className: "flex flex-col gap-2 rounded-lg border border-border bg-card p-4 text-card-foreground shadow-sm", children: kids }));
72
+ default:
73
+ // Unreachable: the gate already refused any non-Basic component.
74
+ return null;
75
+ }
76
+ }
77
+ const RenderChild = ({ node, byId, model, seen }) => _jsx(_Fragment, { children: renderNode(node, byId, model, new Set(seen)) });
78
+ /** Render an already-validated surface against a data model. */
79
+ function A2UISurface({ surface, root, model, }) {
80
+ const byId = useMemo(() => {
81
+ const m = new Map();
82
+ for (const c of surface.components)
83
+ m.set(c.id, c);
84
+ return m;
85
+ }, [surface]);
86
+ const rootNode = byId.get(root);
87
+ if (!rootNode)
88
+ return null;
89
+ return (_jsx("div", { "data-a2ui-surface": surface.surfaceId ?? 'main', "data-trust": "medium", className: cn('flex flex-col gap-2'), children: renderNode(rootNode, byId, model, new Set()) }));
90
+ }
91
+ /**
92
+ * Branch 2 entry point. Runs the standard-catalog-only gate, then renders the
93
+ * surface at medium trust — or signals a fallback and renders nothing.
94
+ */
95
+ export const A2UIRenderer = ({ renderer, event, onFallback }) => {
96
+ const gate = useMemo(() => validateA2uiRenderer(renderer.content, renderer.tags), [renderer.content, renderer.tags]);
97
+ const model = useMemo(() => dataModelFromEvent(event), [event]);
98
+ if (!gate.ok) {
99
+ // The host owns the fallback render (branch 3 iframe / branch 1-4). We only
100
+ // signal; we never render a refused surface at medium trust.
101
+ onFallback?.(gate);
102
+ return null;
103
+ }
104
+ return _jsx(A2UISurface, { surface: gate.surface, root: gate.root, model: model });
105
+ };
106
+ //# sourceMappingURL=A2UIRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"A2UIRenderer.js","sourceRoot":"","sources":["../../src/a2ui/A2UIRenderer.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAA2B,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAmB,MAAM,aAAa,CAAC;AAC9C,OAAO,EAIN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAuB,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAwB3E,sEAAsE;AACtE,SAAS,UAAU,CACjB,IAAuB,EACvB,IAAoC;IAEpC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAC;IAC7C,OAAO,IAAI,CAAC,QAAQ;SACjB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SACzB,MAAM,CAAC,CAAC,CAAC,EAA0B,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AAC5D,CAAC;AAED,kFAAkF;AAClF,SAAS,UAAU,CACjB,IAAuB,EACvB,IAAoC,EACpC,KAAoB,EACpB,IAAiB;IAEjB,iEAAiE;IACjE,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAElB,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,I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,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO,CACL,mCACqB,OAAO,CAAC,SAAS,IAAI,MAAM,gBACnC,QAAQ,EACnB,SAAS,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAEnC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,GACzC,CACP,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAA0B,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE;IACrF,MAAM,IAAI,GAAG,OAAO,CAClB,GAAG,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,EAC3D,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAClC,CAAC;IACF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,4EAA4E;QAC5E,6DAA6D;QAC7D,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAC,WAAW,IAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,GAAI,CAAC;AAC/E,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * A2UI data binding — resolve component-node prop values against the
3
+ * `dataModelUpdate` root, and build that root from a decoded TOON event.
4
+ *
5
+ * A prop value is either a literal (string / number / boolean, or the v0.8
6
+ * `{ literalString }` form) or a `{ path }` JSON-Pointer binding into the data
7
+ * model. Branch 2 binds the *decoded event* as the data-model root, so e.g.
8
+ * `{ "path": "/content" }` resolves to the event's content.
9
+ *
10
+ * Resolution is pure data lookup — no `eval`, no function execution (that would
11
+ * be client-defined behavior, which the gate already refuses).
12
+ */
13
+ import { type NostrEvent, getTagValue } from '../types.js';
14
+ import { type A2uiBoundValue, type A2uiDataModel } from './types.js';
15
+ /**
16
+ * Build the A2UI `dataModelUpdate` root object from a decoded TOON event.
17
+ *
18
+ * The event's first-class fields are exposed at the root so templates can bind
19
+ * `{ path: "/content" }`, `{ path: "/pubkey" }`, `{ path: "/kind" }`, etc.; tags
20
+ * are exposed both raw (`/tags`) and indexed by name (`/tag/<name>` → first
21
+ * value) for ergonomic `{ path: "/tag/title" }`-style binds.
22
+ *
23
+ * NOTE: in production the dispatch hands branch 2 an already-decoded event
24
+ * (`core.decodeEventFromToon(event)`); this helper just projects that
25
+ * `NostrEvent` into the data-model shape. It deliberately does not import
26
+ * `@toon-protocol/core` — the views package stays browser-bundle-safe and the
27
+ * decode happens upstream (see #88 / the toon#36 resolution spike).
28
+ */
29
+ export declare function dataModelFromEvent(event: NostrEvent): A2uiDataModel;
30
+ /**
31
+ * Resolve a JSON Pointer (RFC 6901, e.g. `/content` or `/tag/title`) against the
32
+ * data model. Returns `undefined` for any segment that is missing.
33
+ */
34
+ export declare function resolvePath(model: A2uiDataModel, pointer: string): unknown;
35
+ /**
36
+ * Resolve a bound prop value to a concrete primitive. Literals pass through
37
+ * (including the v0.8 `{ literalString }` form); `{ path }` bindings resolve
38
+ * against the model.
39
+ */
40
+ export declare function resolveValue(value: A2uiBoundValue | unknown, model: A2uiDataModel): unknown;
41
+ /** Resolve a bound value and coerce it to a display string (never throws). */
42
+ export declare function resolveText(value: unknown, model: A2uiDataModel): string;
43
+ /** Read a string prop from a node by name (literal or binding), or `undefined`. */
44
+ export declare function stringProp(node: Record<string, unknown>, name: string, model: A2uiDataModel): string | undefined;
45
+ export { getTagValue };
46
+ //# sourceMappingURL=binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../../src/a2ui/binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CAcnE;AAOD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAY1E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAY3F;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,CAMxE;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,GACnB,MAAM,GAAG,SAAS,CAIpB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * A2UI data binding — resolve component-node prop values against the
3
+ * `dataModelUpdate` root, and build that root from a decoded TOON event.
4
+ *
5
+ * A prop value is either a literal (string / number / boolean, or the v0.8
6
+ * `{ literalString }` form) or a `{ path }` JSON-Pointer binding into the data
7
+ * model. Branch 2 binds the *decoded event* as the data-model root, so e.g.
8
+ * `{ "path": "/content" }` resolves to the event's content.
9
+ *
10
+ * Resolution is pure data lookup — no `eval`, no function execution (that would
11
+ * be client-defined behavior, which the gate already refuses).
12
+ */
13
+ import { getTagValue } from '../types.js';
14
+ import {} from './types.js';
15
+ /**
16
+ * Build the A2UI `dataModelUpdate` root object from a decoded TOON event.
17
+ *
18
+ * The event's first-class fields are exposed at the root so templates can bind
19
+ * `{ path: "/content" }`, `{ path: "/pubkey" }`, `{ path: "/kind" }`, etc.; tags
20
+ * are exposed both raw (`/tags`) and indexed by name (`/tag/<name>` → first
21
+ * value) for ergonomic `{ path: "/tag/title" }`-style binds.
22
+ *
23
+ * NOTE: in production the dispatch hands branch 2 an already-decoded event
24
+ * (`core.decodeEventFromToon(event)`); this helper just projects that
25
+ * `NostrEvent` into the data-model shape. It deliberately does not import
26
+ * `@toon-protocol/core` — the views package stays browser-bundle-safe and the
27
+ * decode happens upstream (see #88 / the toon#36 resolution spike).
28
+ */
29
+ export function dataModelFromEvent(event) {
30
+ const tag = {};
31
+ for (const t of event.tags) {
32
+ if (t[0] !== undefined && t[1] !== undefined && !(t[0] in tag))
33
+ tag[t[0]] = t[1];
34
+ }
35
+ return {
36
+ id: event.id,
37
+ pubkey: event.pubkey,
38
+ created_at: event.created_at,
39
+ kind: event.kind,
40
+ content: event.content,
41
+ tags: event.tags,
42
+ tag,
43
+ };
44
+ }
45
+ /** Type guard: a `{ path }` JSON-Pointer binding. */
46
+ function isPathBinding(v) {
47
+ return typeof v === 'object' && v !== null && typeof v.path === 'string';
48
+ }
49
+ /**
50
+ * Resolve a JSON Pointer (RFC 6901, e.g. `/content` or `/tag/title`) against the
51
+ * data model. Returns `undefined` for any segment that is missing.
52
+ */
53
+ export function resolvePath(model, pointer) {
54
+ if (pointer === '' || pointer === '/')
55
+ return model;
56
+ const segments = pointer
57
+ .replace(/^\//, '')
58
+ .split('/')
59
+ .map((s) => s.replace(/~1/g, '/').replace(/~0/g, '~'));
60
+ let cur = model;
61
+ for (const seg of segments) {
62
+ if (cur == null || typeof cur !== 'object')
63
+ return undefined;
64
+ cur = cur[seg];
65
+ }
66
+ return cur;
67
+ }
68
+ /**
69
+ * Resolve a bound prop value to a concrete primitive. Literals pass through
70
+ * (including the v0.8 `{ literalString }` form); `{ path }` bindings resolve
71
+ * against the model.
72
+ */
73
+ export function resolveValue(value, model) {
74
+ if (value === null)
75
+ return null;
76
+ const t = typeof value;
77
+ if (t === 'string' || t === 'number' || t === 'boolean')
78
+ return value;
79
+ if (isPathBinding(value))
80
+ return resolvePath(model, value.path);
81
+ if (t === 'object') {
82
+ const obj = value;
83
+ if ('literalString' in obj)
84
+ return obj['literalString'];
85
+ if ('literalNumber' in obj)
86
+ return obj['literalNumber'];
87
+ if ('literalBoolean' in obj)
88
+ return obj['literalBoolean'];
89
+ }
90
+ return value;
91
+ }
92
+ /** Resolve a bound value and coerce it to a display string (never throws). */
93
+ export function resolveText(value, model) {
94
+ const resolved = resolveValue(value, model);
95
+ if (resolved == null)
96
+ return '';
97
+ if (typeof resolved === 'string')
98
+ return resolved;
99
+ if (typeof resolved === 'number' || typeof resolved === 'boolean')
100
+ return String(resolved);
101
+ return JSON.stringify(resolved);
102
+ }
103
+ /** Read a string prop from a node by name (literal or binding), or `undefined`. */
104
+ export function stringProp(node, name, model) {
105
+ if (!(name in node) || node[name] === undefined)
106
+ return undefined;
107
+ const resolved = resolveValue(node[name], model);
108
+ return typeof resolved === 'string' ? resolved : resolved == null ? undefined : String(resolved);
109
+ }
110
+ export { getTagValue };
111
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/a2ui/binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAA2C,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB;IAClD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,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;AACnF,MAAM,UAAU,UAAU,CACxB,IAA6B,EAC7B,IAAY,EACZ,KAAoB;IAEpB,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACnG,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Branch 2 — A2UI declarative renderer (medium trust) for the NIP-on-TOON render
3
+ * trust gradient (toon-meta#58, toon-client#89).
4
+ *
5
+ * Renders an A2UI `surfaceUpdate` template bound to a decoded TOON event
6
+ * (`dataModelUpdate`) using the client's own audited "Basic" catalog — never
7
+ * provider code. The standard-catalog-only gate ({@link validateA2uiRenderer})
8
+ * refuses custom components / behavior and signals a drop to branch 3.
9
+ *
10
+ * The React renderer (`A2UIRenderer`) is part of the views *app bundle* (React),
11
+ * not the Node barrel, so it is exported from here rather than `src/index.ts`.
12
+ */
13
+ export { A2UIRenderer, type A2UIRendererProps } from './A2UIRenderer.js';
14
+ export { validateA2uiRenderer, readA2uiVersion, type A2uiGateResult, type A2uiGatePass, type A2uiGateRefuse, type A2uiFallbackBranch, } from './validate.js';
15
+ export { dataModelFromEvent, resolvePath, resolveValue } from './binding.js';
16
+ export { A2UI_BASIC_CATALOG, A2UI_BASIC_CATALOG_SET, SUPPORTED_A2UI_VERSION, SUPPORTED_A2UI_VERSIONS, type A2uiBasicComponent, type A2uiComponentNode, type A2uiSurfaceUpdate, type A2uiDataModel, } from './types.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/a2ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Branch 2 — A2UI declarative renderer (medium trust) for the NIP-on-TOON render
3
+ * trust gradient (toon-meta#58, toon-client#89).
4
+ *
5
+ * Renders an A2UI `surfaceUpdate` template bound to a decoded TOON event
6
+ * (`dataModelUpdate`) using the client's own audited "Basic" catalog — never
7
+ * provider code. The standard-catalog-only gate ({@link validateA2uiRenderer})
8
+ * refuses custom components / behavior and signals a drop to branch 3.
9
+ *
10
+ * The React renderer (`A2UIRenderer`) is part of the views *app bundle* (React),
11
+ * not the Node barrel, so it is exported from here rather than `src/index.ts`.
12
+ */
13
+ export { A2UIRenderer } from './A2UIRenderer.js';
14
+ export { validateA2uiRenderer, readA2uiVersion, } from './validate.js';
15
+ export { dataModelFromEvent, resolvePath, resolveValue } from './binding.js';
16
+ export { A2UI_BASIC_CATALOG, A2UI_BASIC_CATALOG_SET, SUPPORTED_A2UI_VERSION, SUPPORTED_A2UI_VERSIONS, } from './types.js';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/a2ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAA0B,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,eAAe,GAKhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GAKxB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * A2UI message + catalog types for branch 2 of the NIP-on-TOON render trust
3
+ * gradient (toon-meta#58, toon-client#89).
4
+ *
5
+ * Branch 2 renders an **unknown** Nostr kind through the client's *own audited*
6
+ * A2UI catalog at MEDIUM trust — never provider code. The binding convention
7
+ * (spec §"Branch 2 — A2UI binding convention"):
8
+ *
9
+ * - the `kind:31036` renderer's `content` is the A2UI **`surfaceUpdate`** — the
10
+ * durable template stored once on the renderer event, and
11
+ * - the decoded TOON event (`core.decodeEventFromToon` → NostrEvent) is fed in
12
+ * as the **`dataModelUpdate`** — the data bound into the template.
13
+ *
14
+ * These types model the **v0.8-flavoured** A2UI envelope the spec/issue#89 name
15
+ * (`surfaceUpdate` / `dataModelUpdate` / `beginRendering`) using A2UI v0.9's
16
+ * *flattened* component-node shape (`{ id, component: "<Type>", ...props }`),
17
+ * which is what the catalog gate validates. We model only what branch 2 needs;
18
+ * the wider A2UI surface (createSurface/theme/streaming, client-defined
19
+ * functions) is intentionally **out of scope** here — see the deferral notes.
20
+ *
21
+ * Standard-catalog-only invariant (critical): only the A2UI **"Basic"** catalog
22
+ * is permitted at medium trust. Any custom/non-standard component reference, or
23
+ * any client-defined behavior, must REFUSE to render here and signal a drop to
24
+ * branch 3 (sandboxed mcp-ui). Enforcement lives in `validate.ts`.
25
+ */
26
+ /**
27
+ * The A2UI **Basic** (standard) catalog component types we support at medium
28
+ * trust. Deliberately a *curated, presentational* subset of the published Basic
29
+ * catalog: static layout + content components that are safe to render from
30
+ * untrusted template data with no client-defined behavior.
31
+ *
32
+ * Components in the published Basic catalog that imply behavior / interactivity
33
+ * or client-defined functions (Button actions, TextField/CheckBox/Slider/
34
+ * ChoicePicker/DateTimeInput inputs, Modal, Tabs, Video/AudioPlayer) are
35
+ * intentionally NOT in this set: branch 2 is a *read-only* binding of decoded
36
+ * event data into a template. A surface that references them is treated as
37
+ * carrying custom behavior and is dropped to branch 3. (Deferred — see #90.)
38
+ */
39
+ export declare const A2UI_BASIC_CATALOG: readonly ["Text", "Heading", "Image", "Icon", "Row", "Column", "List", "Card", "Divider"];
40
+ /** A supported Basic-catalog component type. */
41
+ export type A2uiBasicComponent = (typeof A2UI_BASIC_CATALOG)[number];
42
+ /** O(1) membership set for the catalog gate. */
43
+ export declare const A2UI_BASIC_CATALOG_SET: ReadonlySet<string>;
44
+ /**
45
+ * The A2UI version this renderer implements. The `["a2ui", "<version>"]` tag on
46
+ * the `kind:31036` renderer is checked against this; an unsupported version
47
+ * falls through gracefully (the dispatch can route to branch 1/4). We accept the
48
+ * v0.8 binding-convention vocabulary the spec names.
49
+ */
50
+ export declare const SUPPORTED_A2UI_VERSION = "v0.8";
51
+ /**
52
+ * Versions this renderer accepts. A renderer with no `["a2ui", …]` tag is
53
+ * treated as the supported default (the `m`-tag already selected A2UI).
54
+ */
55
+ export declare const SUPPORTED_A2UI_VERSIONS: ReadonlySet<string>;
56
+ /**
57
+ * A data-bound property value: either a literal, or a `{ path }` JSON-Pointer
58
+ * binding into the `dataModelUpdate` root. We accept both the v0.9 short form
59
+ * (`{ path: "/a/b" }`) and the v0.8 long form (`{ literalString: "…" }`).
60
+ */
61
+ export type A2uiBoundValue = string | number | boolean | {
62
+ path: string;
63
+ } | {
64
+ literalString: string;
65
+ } | {
66
+ literalNumber: number;
67
+ } | {
68
+ literalBoolean: boolean;
69
+ };
70
+ /**
71
+ * A single A2UI component node (flattened form). `component` names the type;
72
+ * `children` references child node ids; all other keys are component props that
73
+ * may carry literals or `{ path }` bindings.
74
+ */
75
+ export interface A2uiComponentNode {
76
+ /** Unique node id. The tree root has `id: "root"` by convention. */
77
+ id: string;
78
+ /** The component type name (validated against the Basic catalog). */
79
+ component: string;
80
+ /** Child node ids (for container components: Row / Column / List / Card). */
81
+ children?: string[];
82
+ /** Remaining props (literals or `{ path }` bindings). */
83
+ [prop: string]: unknown;
84
+ }
85
+ /** The `surfaceUpdate` carried in the `kind:31036` renderer `content`. */
86
+ export interface A2uiSurfaceUpdate {
87
+ surfaceId?: string;
88
+ /** The flat list of component nodes making up the template. */
89
+ components: A2uiComponentNode[];
90
+ /**
91
+ * Optional explicit root id (v0.8 `beginRendering.root`). Defaults to the node
92
+ * with `id: "root"`, else the first component.
93
+ */
94
+ root?: string;
95
+ }
96
+ /**
97
+ * The `dataModelUpdate` — the root data object bound into the template. Branch 2
98
+ * feeds the decoded TOON event here (see {@link dataModelFromEvent}).
99
+ */
100
+ export type A2uiDataModel = Record<string, unknown>;
101
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/a2ui/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,kBAAkB,2FAUrB,CAAC;AAEX,gDAAgD;AAChD,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,gDAAgD;AAChD,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,MAAM,CAA+B,CAAC;AAEvF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAAqC,CAAC;AAE9F;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,cAAc,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,yDAAyD;IACzD,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * A2UI message + catalog types for branch 2 of the NIP-on-TOON render trust
3
+ * gradient (toon-meta#58, toon-client#89).
4
+ *
5
+ * Branch 2 renders an **unknown** Nostr kind through the client's *own audited*
6
+ * A2UI catalog at MEDIUM trust — never provider code. The binding convention
7
+ * (spec §"Branch 2 — A2UI binding convention"):
8
+ *
9
+ * - the `kind:31036` renderer's `content` is the A2UI **`surfaceUpdate`** — the
10
+ * durable template stored once on the renderer event, and
11
+ * - the decoded TOON event (`core.decodeEventFromToon` → NostrEvent) is fed in
12
+ * as the **`dataModelUpdate`** — the data bound into the template.
13
+ *
14
+ * These types model the **v0.8-flavoured** A2UI envelope the spec/issue#89 name
15
+ * (`surfaceUpdate` / `dataModelUpdate` / `beginRendering`) using A2UI v0.9's
16
+ * *flattened* component-node shape (`{ id, component: "<Type>", ...props }`),
17
+ * which is what the catalog gate validates. We model only what branch 2 needs;
18
+ * the wider A2UI surface (createSurface/theme/streaming, client-defined
19
+ * functions) is intentionally **out of scope** here — see the deferral notes.
20
+ *
21
+ * Standard-catalog-only invariant (critical): only the A2UI **"Basic"** catalog
22
+ * is permitted at medium trust. Any custom/non-standard component reference, or
23
+ * any client-defined behavior, must REFUSE to render here and signal a drop to
24
+ * branch 3 (sandboxed mcp-ui). Enforcement lives in `validate.ts`.
25
+ */
26
+ /**
27
+ * The A2UI **Basic** (standard) catalog component types we support at medium
28
+ * trust. Deliberately a *curated, presentational* subset of the published Basic
29
+ * catalog: static layout + content components that are safe to render from
30
+ * untrusted template data with no client-defined behavior.
31
+ *
32
+ * Components in the published Basic catalog that imply behavior / interactivity
33
+ * or client-defined functions (Button actions, TextField/CheckBox/Slider/
34
+ * ChoicePicker/DateTimeInput inputs, Modal, Tabs, Video/AudioPlayer) are
35
+ * intentionally NOT in this set: branch 2 is a *read-only* binding of decoded
36
+ * event data into a template. A surface that references them is treated as
37
+ * carrying custom behavior and is dropped to branch 3. (Deferred — see #90.)
38
+ */
39
+ export const A2UI_BASIC_CATALOG = [
40
+ 'Text',
41
+ 'Heading',
42
+ 'Image',
43
+ 'Icon',
44
+ 'Row',
45
+ 'Column',
46
+ 'List',
47
+ 'Card',
48
+ 'Divider',
49
+ ];
50
+ /** O(1) membership set for the catalog gate. */
51
+ export const A2UI_BASIC_CATALOG_SET = new Set(A2UI_BASIC_CATALOG);
52
+ /**
53
+ * The A2UI version this renderer implements. The `["a2ui", "<version>"]` tag on
54
+ * the `kind:31036` renderer is checked against this; an unsupported version
55
+ * falls through gracefully (the dispatch can route to branch 1/4). We accept the
56
+ * v0.8 binding-convention vocabulary the spec names.
57
+ */
58
+ export const SUPPORTED_A2UI_VERSION = 'v0.8';
59
+ /**
60
+ * Versions this renderer accepts. A renderer with no `["a2ui", …]` tag is
61
+ * treated as the supported default (the `m`-tag already selected A2UI).
62
+ */
63
+ export const SUPPORTED_A2UI_VERSIONS = new Set([SUPPORTED_A2UI_VERSION]);
64
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/a2ui/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM;IACN,SAAS;IACT,OAAO;IACP,MAAM;IACN,KAAK;IACL,QAAQ;IACR,MAAM;IACN,MAAM;IACN,SAAS;CACD,CAAC;AAKX,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEvF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The standard-catalog-only validation gate for branch 2 (A2UI, medium trust).
3
+ *
4
+ * This is the security boundary of the A2UI branch. Medium trust is reserved for
5
+ * renderers that stay ENTIRELY within the A2UI "Basic" standard catalog and
6
+ * carry no client-defined behavior. Anything else must be REFUSED here and
7
+ * dropped to branch 3 (the sandboxed mcp-ui path) — never rendered at medium
8
+ * trust against the client's own primitives.
9
+ *
10
+ * The gate returns a discriminated {@link A2uiGateResult}:
11
+ * - `{ ok: true, surface, root }` → render at medium trust, or
12
+ * - `{ ok: false, fallback: 'mcp-ui', … }` → drop to branch 3 (custom comp /
13
+ * behavior), or
14
+ * - `{ ok: false, fallback: 'native', … }` → unsupported A2UI version /
15
+ * unparseable; let the dispatch
16
+ * fall through (branch 1/4).
17
+ *
18
+ * The renderer NEVER renders a surface the gate refused.
19
+ */
20
+ import { type A2uiSurfaceUpdate } from './types.js';
21
+ /** Where a refusal sends the event next. */
22
+ export type A2uiFallbackBranch = 'mcp-ui' | 'native';
23
+ /** A passed gate: the parsed surface + resolved root id, safe to render. */
24
+ export interface A2uiGatePass {
25
+ ok: true;
26
+ surface: A2uiSurfaceUpdate;
27
+ /** Resolved root node id (`"root"` by convention, else explicit/first). */
28
+ root: string;
29
+ }
30
+ /**
31
+ * A refused gate. `fallback` names the branch the dispatch should drop to:
32
+ * `'mcp-ui'` for the standard-catalog-only invariant (custom component or custom
33
+ * behavior present), `'native'` for an unsupported/unparseable renderer that
34
+ * should fall through to branch 1/4.
35
+ */
36
+ export interface A2uiGateRefuse {
37
+ ok: false;
38
+ fallback: A2uiFallbackBranch;
39
+ /** Stable machine reason, safe to log. */
40
+ reason: 'unsupported-version' | 'unparseable-surface' | 'empty-surface' | 'custom-component' | 'custom-behavior' | 'missing-root';
41
+ /** Human-readable detail (e.g. the offending component name). */
42
+ detail: string;
43
+ }
44
+ export type A2uiGateResult = A2uiGatePass | A2uiGateRefuse;
45
+ /** Read the `["a2ui", "<version>"]` tag value, or `undefined`. */
46
+ export declare function readA2uiVersion(tags: string[][]): string | undefined;
47
+ /**
48
+ * Validate the A2UI renderer for branch 2.
49
+ *
50
+ * @param content the `kind:31036` renderer `content` (the JSON `surfaceUpdate`)
51
+ * @param tags the renderer event tags (read for the `a2ui` version tag)
52
+ * @returns a {@link A2uiGateResult} — pass (render) or refuse (fall back).
53
+ */
54
+ export declare function validateA2uiRenderer(content: string, tags: string[][]): A2uiGateResult;
55
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/a2ui/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AAEpB,4CAA4C;AAC5C,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErD,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,IAAI,CAAC;IACT,OAAO,EAAE,iBAAiB,CAAC;IAC3B,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,KAAK,CAAC;IACV,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,0CAA0C;IAC1C,MAAM,EACF,qBAAqB,GACrB,qBAAqB,GACrB,eAAe,GACf,kBAAkB,GAClB,iBAAiB,GACjB,cAAc,CAAC;IACnB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,cAAc,CAAC;AAU3D,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,SAAS,CAGpE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,cAAc,CAqEtF"}