@elastic/isomer-sdk 0.0.0 → 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 (492) hide show
  1. package/LICENSE.txt +93 -0
  2. package/NOTICE.txt +1861 -0
  3. package/README.md +69 -0
  4. package/THIRD_PARTY_LICENSES.md +957 -0
  5. package/dist/author/authored_fields.d.ts +153 -0
  6. package/dist/author/authored_fields.d.ts.map +1 -0
  7. package/dist/author/authored_fields.js +227 -0
  8. package/dist/author/authored_fields.js.map +1 -0
  9. package/dist/author/authoring_input.d.ts +7 -0
  10. package/dist/author/authoring_input.d.ts.map +1 -0
  11. package/dist/author/authoring_input.js +60 -0
  12. package/dist/author/authoring_input.js.map +1 -0
  13. package/dist/author/authoring_model.d.ts +27 -0
  14. package/dist/author/authoring_model.d.ts.map +1 -0
  15. package/dist/author/authoring_model.js +98 -0
  16. package/dist/author/authoring_model.js.map +1 -0
  17. package/dist/author/declarations.d.ts +13 -0
  18. package/dist/author/declarations.d.ts.map +1 -0
  19. package/dist/author/declarations.js +277 -0
  20. package/dist/author/declarations.js.map +1 -0
  21. package/dist/author/index.d.ts +7 -0
  22. package/dist/author/index.d.ts.map +1 -0
  23. package/dist/author/index.js +12 -0
  24. package/dist/author/index.js.map +1 -0
  25. package/dist/author/jsx.d.ts +21 -0
  26. package/dist/author/jsx.d.ts.map +1 -0
  27. package/dist/author/jsx.js +20 -0
  28. package/dist/author/jsx.js.map +1 -0
  29. package/dist/author/jsx_shim.d.ts +117 -0
  30. package/dist/author/jsx_shim.d.ts.map +1 -0
  31. package/dist/author/jsx_shim.js +270 -0
  32. package/dist/author/jsx_shim.js.map +1 -0
  33. package/dist/author/prompt.d.ts +58 -0
  34. package/dist/author/prompt.d.ts.map +1 -0
  35. package/dist/author/prompt.js +148 -0
  36. package/dist/author/prompt.js.map +1 -0
  37. package/dist/author/schema_to_typescript.d.ts +37 -0
  38. package/dist/author/schema_to_typescript.d.ts.map +1 -0
  39. package/dist/author/schema_to_typescript.js +286 -0
  40. package/dist/author/schema_to_typescript.js.map +1 -0
  41. package/dist/cjs/author/authored_fields.js +233 -0
  42. package/dist/cjs/author/authored_fields.js.map +1 -0
  43. package/dist/cjs/author/authoring_input.js +64 -0
  44. package/dist/cjs/author/authoring_input.js.map +1 -0
  45. package/dist/cjs/author/authoring_model.js +104 -0
  46. package/dist/cjs/author/authoring_model.js.map +1 -0
  47. package/dist/cjs/author/declarations.js +281 -0
  48. package/dist/cjs/author/declarations.js.map +1 -0
  49. package/dist/cjs/author/index.js +25 -0
  50. package/dist/cjs/author/index.js.map +1 -0
  51. package/dist/cjs/author/jsx.js +24 -0
  52. package/dist/cjs/author/jsx.js.map +1 -0
  53. package/dist/cjs/author/jsx_shim.js +276 -0
  54. package/dist/cjs/author/jsx_shim.js.map +1 -0
  55. package/dist/cjs/author/prompt.js +153 -0
  56. package/dist/cjs/author/prompt.js.map +1 -0
  57. package/dist/cjs/author/schema_to_typescript.js +295 -0
  58. package/dist/cjs/author/schema_to_typescript.js.map +1 -0
  59. package/dist/cjs/composition/action_event.js +9 -0
  60. package/dist/cjs/composition/action_event.js.map +1 -0
  61. package/dist/cjs/composition/body_node_base.js +112 -0
  62. package/dist/cjs/composition/body_node_base.js.map +1 -0
  63. package/dist/cjs/composition/composition.js +9 -0
  64. package/dist/cjs/composition/composition.js.map +1 -0
  65. package/dist/cjs/composition/error.js +73 -0
  66. package/dist/cjs/composition/error.js.map +1 -0
  67. package/dist/cjs/composition/index.js +32 -0
  68. package/dist/cjs/composition/index.js.map +1 -0
  69. package/dist/cjs/composition/map_nodes.js +85 -0
  70. package/dist/cjs/composition/map_nodes.js.map +1 -0
  71. package/dist/cjs/composition/named_color.js +20 -0
  72. package/dist/cjs/composition/named_color.js.map +1 -0
  73. package/dist/cjs/composition/node.js +9 -0
  74. package/dist/cjs/composition/node.js.map +1 -0
  75. package/dist/cjs/composition/one_line.js +23 -0
  76. package/dist/cjs/composition/one_line.js.map +1 -0
  77. package/dist/cjs/composition/structured_value.js +21 -0
  78. package/dist/cjs/composition/structured_value.js.map +1 -0
  79. package/dist/cjs/composition/validation_error.js +40 -0
  80. package/dist/cjs/composition/validation_error.js.map +1 -0
  81. package/dist/cjs/define/frame.js +31 -0
  82. package/dist/cjs/define/frame.js.map +1 -0
  83. package/dist/cjs/define/index.js +31 -0
  84. package/dist/cjs/define/index.js.map +1 -0
  85. package/dist/cjs/define/markdown_content.js +12 -0
  86. package/dist/cjs/define/markdown_content.js.map +1 -0
  87. package/dist/cjs/define/primitive_example.js +26 -0
  88. package/dist/cjs/define/primitive_example.js.map +1 -0
  89. package/dist/cjs/define/primitive_icon.js +17 -0
  90. package/dist/cjs/define/primitive_icon.js.map +1 -0
  91. package/dist/cjs/define/primitive_module.js +118 -0
  92. package/dist/cjs/define/primitive_module.js.map +1 -0
  93. package/dist/cjs/define/slack_assets.js +9 -0
  94. package/dist/cjs/define/slack_assets.js.map +1 -0
  95. package/dist/cjs/define/slack_blocks.js +9 -0
  96. package/dist/cjs/define/slack_blocks.js.map +1 -0
  97. package/dist/cjs/define/zod_format.js +122 -0
  98. package/dist/cjs/define/zod_format.js.map +1 -0
  99. package/dist/cjs/define/zod_helpers.js +26 -0
  100. package/dist/cjs/define/zod_helpers.js.map +1 -0
  101. package/dist/cjs/entries/html.js +12 -0
  102. package/dist/cjs/entries/html.js.map +1 -0
  103. package/dist/cjs/entries/index.js +80 -0
  104. package/dist/cjs/entries/index.js.map +1 -0
  105. package/dist/cjs/entries/markdown.js +14 -0
  106. package/dist/cjs/entries/markdown.js.map +1 -0
  107. package/dist/cjs/entries/react.js +20 -0
  108. package/dist/cjs/entries/react.js.map +1 -0
  109. package/dist/cjs/entries/slack.js +25 -0
  110. package/dist/cjs/entries/slack.js.map +1 -0
  111. package/dist/cjs/entries/text.js +12 -0
  112. package/dist/cjs/entries/text.js.map +1 -0
  113. package/dist/cjs/pack/capabilities.js +40 -0
  114. package/dist/cjs/pack/capabilities.js.map +1 -0
  115. package/dist/cjs/pack/compose.js +59 -0
  116. package/dist/cjs/pack/compose.js.map +1 -0
  117. package/dist/cjs/pack/enhancements.js +65 -0
  118. package/dist/cjs/pack/enhancements.js.map +1 -0
  119. package/dist/cjs/pack/index.js +18 -0
  120. package/dist/cjs/pack/index.js.map +1 -0
  121. package/dist/cjs/pack/primitive_pack.js +97 -0
  122. package/dist/cjs/pack/primitive_pack.js.map +1 -0
  123. package/dist/cjs/package.json +3 -0
  124. package/dist/cjs/render/anchors.js +167 -0
  125. package/dist/cjs/render/anchors.js.map +1 -0
  126. package/dist/cjs/render/context_view.js +54 -0
  127. package/dist/cjs/render/context_view.js.map +1 -0
  128. package/dist/cjs/render/format_display_value.js +143 -0
  129. package/dist/cjs/render/format_display_value.js.map +1 -0
  130. package/dist/cjs/render/format_number.js +46 -0
  131. package/dist/cjs/render/format_number.js.map +1 -0
  132. package/dist/cjs/render/html/enhancements.js +30 -0
  133. package/dist/cjs/render/html/enhancements.js.map +1 -0
  134. package/dist/cjs/render/html/envelope.js +218 -0
  135. package/dist/cjs/render/html/envelope.js.map +1 -0
  136. package/dist/cjs/render/html/index.js +12 -0
  137. package/dist/cjs/render/html/index.js.map +1 -0
  138. package/dist/cjs/render/index.js +25 -0
  139. package/dist/cjs/render/index.js.map +1 -0
  140. package/dist/cjs/render/layout_check.js +133 -0
  141. package/dist/cjs/render/layout_check.js.map +1 -0
  142. package/dist/cjs/render/markdown/builder.js +195 -0
  143. package/dist/cjs/render/markdown/builder.js.map +1 -0
  144. package/dist/cjs/render/markdown/envelope.js +33 -0
  145. package/dist/cjs/render/markdown/envelope.js.map +1 -0
  146. package/dist/cjs/render/markdown/format.js +208 -0
  147. package/dist/cjs/render/markdown/format.js.map +1 -0
  148. package/dist/cjs/render/markdown/index.js +15 -0
  149. package/dist/cjs/render/markdown/index.js.map +1 -0
  150. package/dist/cjs/render/measure_dom.js +61 -0
  151. package/dist/cjs/render/measure_dom.js.map +1 -0
  152. package/dist/cjs/render/payload.js +13 -0
  153. package/dist/cjs/render/payload.js.map +1 -0
  154. package/dist/cjs/render/primitive_dispatch.js +173 -0
  155. package/dist/cjs/render/primitive_dispatch.js.map +1 -0
  156. package/dist/cjs/render/react/content.js +44 -0
  157. package/dist/cjs/render/react/content.js.map +1 -0
  158. package/dist/cjs/render/react/enhancements.js +32 -0
  159. package/dist/cjs/render/react/enhancements.js.map +1 -0
  160. package/dist/cjs/render/react/index.js +15 -0
  161. package/dist/cjs/render/react/index.js.map +1 -0
  162. package/dist/cjs/render/slack/assets.js +45 -0
  163. package/dist/cjs/render/slack/assets.js.map +1 -0
  164. package/dist/cjs/render/slack/blocks.js +80 -0
  165. package/dist/cjs/render/slack/blocks.js.map +1 -0
  166. package/dist/cjs/render/slack/envelope.js +551 -0
  167. package/dist/cjs/render/slack/envelope.js.map +1 -0
  168. package/dist/cjs/render/slack/format.js +225 -0
  169. package/dist/cjs/render/slack/format.js.map +1 -0
  170. package/dist/cjs/render/slack/index.js +30 -0
  171. package/dist/cjs/render/slack/index.js.map +1 -0
  172. package/dist/cjs/render/slack/markdown_content.js +409 -0
  173. package/dist/cjs/render/slack/markdown_content.js.map +1 -0
  174. package/dist/cjs/render/text/envelope.js +21 -0
  175. package/dist/cjs/render/text/envelope.js.map +1 -0
  176. package/dist/cjs/render/text/index.js +12 -0
  177. package/dist/cjs/render/text/index.js.map +1 -0
  178. package/dist/cjs/testing/conformance.js +312 -0
  179. package/dist/cjs/testing/conformance.js.map +1 -0
  180. package/dist/cjs/testing/icon.js +248 -0
  181. package/dist/cjs/testing/icon.js.map +1 -0
  182. package/dist/cjs/testing/index.js +18 -0
  183. package/dist/cjs/testing/index.js.map +1 -0
  184. package/dist/cjs/testing/registration.js +142 -0
  185. package/dist/cjs/testing/registration.js.map +1 -0
  186. package/dist/cjs/validate/authoring_schema.js +312 -0
  187. package/dist/cjs/validate/authoring_schema.js.map +1 -0
  188. package/dist/cjs/validate/composition_schema.js +135 -0
  189. package/dist/cjs/validate/composition_schema.js.map +1 -0
  190. package/dist/cjs/validate/index.js +53 -0
  191. package/dist/cjs/validate/index.js.map +1 -0
  192. package/dist/cjs/validate/input_budget.js +156 -0
  193. package/dist/cjs/validate/input_budget.js.map +1 -0
  194. package/dist/cjs/validate/json_schema.js +72 -0
  195. package/dist/cjs/validate/json_schema.js.map +1 -0
  196. package/dist/cjs/validate/node_issues.js +65 -0
  197. package/dist/cjs/validate/node_issues.js.map +1 -0
  198. package/dist/cjs/validate/url.js +116 -0
  199. package/dist/cjs/validate/url.js.map +1 -0
  200. package/dist/cjs/validate/validation.js +165 -0
  201. package/dist/cjs/validate/validation.js.map +1 -0
  202. package/dist/cjs/validate/value_schemas.js +53 -0
  203. package/dist/cjs/validate/value_schemas.js.map +1 -0
  204. package/dist/composition/action_event.d.ts +13 -0
  205. package/dist/composition/action_event.d.ts.map +1 -0
  206. package/dist/composition/action_event.js +8 -0
  207. package/dist/composition/action_event.js.map +1 -0
  208. package/dist/composition/body_node_base.d.ts +72 -0
  209. package/dist/composition/body_node_base.d.ts.map +1 -0
  210. package/dist/composition/body_node_base.js +104 -0
  211. package/dist/composition/body_node_base.js.map +1 -0
  212. package/dist/composition/composition.d.ts +71 -0
  213. package/dist/composition/composition.d.ts.map +1 -0
  214. package/dist/composition/composition.js +8 -0
  215. package/dist/composition/composition.js.map +1 -0
  216. package/dist/composition/error.d.ts +61 -0
  217. package/dist/composition/error.d.ts.map +1 -0
  218. package/dist/composition/error.js +69 -0
  219. package/dist/composition/error.js.map +1 -0
  220. package/dist/composition/index.d.ts +11 -0
  221. package/dist/composition/index.d.ts.map +1 -0
  222. package/dist/composition/index.js +14 -0
  223. package/dist/composition/index.js.map +1 -0
  224. package/dist/composition/map_nodes.d.ts +16 -0
  225. package/dist/composition/map_nodes.d.ts.map +1 -0
  226. package/dist/composition/map_nodes.js +81 -0
  227. package/dist/composition/map_nodes.js.map +1 -0
  228. package/dist/composition/named_color.d.ts +9 -0
  229. package/dist/composition/named_color.d.ts.map +1 -0
  230. package/dist/composition/named_color.js +17 -0
  231. package/dist/composition/named_color.js.map +1 -0
  232. package/dist/composition/node.d.ts +11 -0
  233. package/dist/composition/node.d.ts.map +1 -0
  234. package/dist/composition/node.js +8 -0
  235. package/dist/composition/node.js.map +1 -0
  236. package/dist/composition/one_line.d.ts +7 -0
  237. package/dist/composition/one_line.d.ts.map +1 -0
  238. package/dist/composition/one_line.js +17 -0
  239. package/dist/composition/one_line.js.map +1 -0
  240. package/dist/composition/structured_value.d.ts +27 -0
  241. package/dist/composition/structured_value.d.ts.map +1 -0
  242. package/dist/composition/structured_value.js +18 -0
  243. package/dist/composition/structured_value.js.map +1 -0
  244. package/dist/composition/validation_error.d.ts +33 -0
  245. package/dist/composition/validation_error.d.ts.map +1 -0
  246. package/dist/composition/validation_error.js +35 -0
  247. package/dist/composition/validation_error.js.map +1 -0
  248. package/dist/define/frame.d.ts +155 -0
  249. package/dist/define/frame.d.ts.map +1 -0
  250. package/dist/define/frame.js +27 -0
  251. package/dist/define/frame.js.map +1 -0
  252. package/dist/define/index.d.ts +10 -0
  253. package/dist/define/index.d.ts.map +1 -0
  254. package/dist/define/index.js +13 -0
  255. package/dist/define/index.js.map +1 -0
  256. package/dist/define/markdown_content.d.ts +15 -0
  257. package/dist/define/markdown_content.d.ts.map +1 -0
  258. package/dist/define/markdown_content.js +9 -0
  259. package/dist/define/markdown_content.js.map +1 -0
  260. package/dist/define/primitive_example.d.ts +30 -0
  261. package/dist/define/primitive_example.d.ts.map +1 -0
  262. package/dist/define/primitive_example.js +21 -0
  263. package/dist/define/primitive_example.js.map +1 -0
  264. package/dist/define/primitive_icon.d.ts +11 -0
  265. package/dist/define/primitive_icon.d.ts.map +1 -0
  266. package/dist/define/primitive_icon.js +14 -0
  267. package/dist/define/primitive_icon.js.map +1 -0
  268. package/dist/define/primitive_module.d.ts +435 -0
  269. package/dist/define/primitive_module.d.ts.map +1 -0
  270. package/dist/define/primitive_module.js +112 -0
  271. package/dist/define/primitive_module.js.map +1 -0
  272. package/dist/define/slack_assets.d.ts +28 -0
  273. package/dist/define/slack_assets.d.ts.map +1 -0
  274. package/dist/define/slack_assets.js +8 -0
  275. package/dist/define/slack_assets.js.map +1 -0
  276. package/dist/define/slack_blocks.d.ts +234 -0
  277. package/dist/define/slack_blocks.d.ts.map +1 -0
  278. package/dist/define/slack_blocks.js +8 -0
  279. package/dist/define/slack_blocks.js.map +1 -0
  280. package/dist/define/zod_format.d.ts +33 -0
  281. package/dist/define/zod_format.d.ts.map +1 -0
  282. package/dist/define/zod_format.js +114 -0
  283. package/dist/define/zod_format.js.map +1 -0
  284. package/dist/define/zod_helpers.d.ts +10 -0
  285. package/dist/define/zod_helpers.d.ts.map +1 -0
  286. package/dist/define/zod_helpers.js +22 -0
  287. package/dist/define/zod_helpers.js.map +1 -0
  288. package/dist/entries/html.d.ts +3 -0
  289. package/dist/entries/html.d.ts.map +1 -0
  290. package/dist/entries/html.js +8 -0
  291. package/dist/entries/html.js.map +1 -0
  292. package/dist/entries/index.d.ts +6 -0
  293. package/dist/entries/index.d.ts.map +1 -0
  294. package/dist/entries/index.js +12 -0
  295. package/dist/entries/index.js.map +1 -0
  296. package/dist/entries/markdown.d.ts +3 -0
  297. package/dist/entries/markdown.d.ts.map +1 -0
  298. package/dist/entries/markdown.js +8 -0
  299. package/dist/entries/markdown.js.map +1 -0
  300. package/dist/entries/react.d.ts +5 -0
  301. package/dist/entries/react.d.ts.map +1 -0
  302. package/dist/entries/react.js +11 -0
  303. package/dist/entries/react.js.map +1 -0
  304. package/dist/entries/slack.d.ts +2 -0
  305. package/dist/entries/slack.d.ts.map +1 -0
  306. package/dist/entries/slack.js +8 -0
  307. package/dist/entries/slack.js.map +1 -0
  308. package/dist/entries/text.d.ts +2 -0
  309. package/dist/entries/text.d.ts.map +1 -0
  310. package/dist/entries/text.js +8 -0
  311. package/dist/entries/text.js.map +1 -0
  312. package/dist/pack/capabilities.d.ts +41 -0
  313. package/dist/pack/capabilities.d.ts.map +1 -0
  314. package/dist/pack/capabilities.js +36 -0
  315. package/dist/pack/capabilities.js.map +1 -0
  316. package/dist/pack/compose.d.ts +24 -0
  317. package/dist/pack/compose.d.ts.map +1 -0
  318. package/dist/pack/compose.js +55 -0
  319. package/dist/pack/compose.js.map +1 -0
  320. package/dist/pack/enhancements.d.ts +65 -0
  321. package/dist/pack/enhancements.d.ts.map +1 -0
  322. package/dist/pack/enhancements.js +59 -0
  323. package/dist/pack/enhancements.js.map +1 -0
  324. package/dist/pack/index.d.ts +5 -0
  325. package/dist/pack/index.d.ts.map +1 -0
  326. package/dist/pack/index.js +11 -0
  327. package/dist/pack/index.js.map +1 -0
  328. package/dist/pack/primitive_pack.d.ts +164 -0
  329. package/dist/pack/primitive_pack.d.ts.map +1 -0
  330. package/dist/pack/primitive_pack.js +92 -0
  331. package/dist/pack/primitive_pack.js.map +1 -0
  332. package/dist/render/anchors.d.ts +82 -0
  333. package/dist/render/anchors.d.ts.map +1 -0
  334. package/dist/render/anchors.js +153 -0
  335. package/dist/render/anchors.js.map +1 -0
  336. package/dist/render/context_view.d.ts +10 -0
  337. package/dist/render/context_view.d.ts.map +1 -0
  338. package/dist/render/context_view.js +49 -0
  339. package/dist/render/context_view.js.map +1 -0
  340. package/dist/render/format_display_value.d.ts +20 -0
  341. package/dist/render/format_display_value.d.ts.map +1 -0
  342. package/dist/render/format_display_value.js +137 -0
  343. package/dist/render/format_display_value.js.map +1 -0
  344. package/dist/render/format_number.d.ts +9 -0
  345. package/dist/render/format_number.d.ts.map +1 -0
  346. package/dist/render/format_number.js +42 -0
  347. package/dist/render/format_number.js.map +1 -0
  348. package/dist/render/html/enhancements.d.ts +10 -0
  349. package/dist/render/html/enhancements.d.ts.map +1 -0
  350. package/dist/render/html/enhancements.js +25 -0
  351. package/dist/render/html/enhancements.js.map +1 -0
  352. package/dist/render/html/envelope.d.ts +182 -0
  353. package/dist/render/html/envelope.d.ts.map +1 -0
  354. package/dist/render/html/envelope.js +214 -0
  355. package/dist/render/html/envelope.js.map +1 -0
  356. package/dist/render/html/index.d.ts +3 -0
  357. package/dist/render/html/index.d.ts.map +1 -0
  358. package/dist/render/html/index.js +8 -0
  359. package/dist/render/html/index.js.map +1 -0
  360. package/dist/render/index.d.ts +6 -0
  361. package/dist/render/index.d.ts.map +1 -0
  362. package/dist/render/index.js +11 -0
  363. package/dist/render/index.js.map +1 -0
  364. package/dist/render/layout_check.d.ts +43 -0
  365. package/dist/render/layout_check.d.ts.map +1 -0
  366. package/dist/render/layout_check.js +129 -0
  367. package/dist/render/layout_check.js.map +1 -0
  368. package/dist/render/markdown/builder.d.ts +46 -0
  369. package/dist/render/markdown/builder.d.ts.map +1 -0
  370. package/dist/render/markdown/builder.js +190 -0
  371. package/dist/render/markdown/builder.js.map +1 -0
  372. package/dist/render/markdown/envelope.d.ts +20 -0
  373. package/dist/render/markdown/envelope.d.ts.map +1 -0
  374. package/dist/render/markdown/envelope.js +29 -0
  375. package/dist/render/markdown/envelope.js.map +1 -0
  376. package/dist/render/markdown/format.d.ts +10 -0
  377. package/dist/render/markdown/format.d.ts.map +1 -0
  378. package/dist/render/markdown/format.js +202 -0
  379. package/dist/render/markdown/format.js.map +1 -0
  380. package/dist/render/markdown/index.d.ts +3 -0
  381. package/dist/render/markdown/index.d.ts.map +1 -0
  382. package/dist/render/markdown/index.js +9 -0
  383. package/dist/render/markdown/index.js.map +1 -0
  384. package/dist/render/measure_dom.d.ts +10 -0
  385. package/dist/render/measure_dom.d.ts.map +1 -0
  386. package/dist/render/measure_dom.js +57 -0
  387. package/dist/render/measure_dom.js.map +1 -0
  388. package/dist/render/payload.d.ts +16 -0
  389. package/dist/render/payload.d.ts.map +1 -0
  390. package/dist/render/payload.js +9 -0
  391. package/dist/render/payload.js.map +1 -0
  392. package/dist/render/primitive_dispatch.d.ts +72 -0
  393. package/dist/render/primitive_dispatch.d.ts.map +1 -0
  394. package/dist/render/primitive_dispatch.js +169 -0
  395. package/dist/render/primitive_dispatch.js.map +1 -0
  396. package/dist/render/react/content.d.ts +40 -0
  397. package/dist/render/react/content.d.ts.map +1 -0
  398. package/dist/render/react/content.js +39 -0
  399. package/dist/render/react/content.js.map +1 -0
  400. package/dist/render/react/enhancements.d.ts +15 -0
  401. package/dist/render/react/enhancements.d.ts.map +1 -0
  402. package/dist/render/react/enhancements.js +28 -0
  403. package/dist/render/react/enhancements.js.map +1 -0
  404. package/dist/render/react/index.d.ts +3 -0
  405. package/dist/render/react/index.d.ts.map +1 -0
  406. package/dist/render/react/index.js +9 -0
  407. package/dist/render/react/index.js.map +1 -0
  408. package/dist/render/slack/assets.d.ts +16 -0
  409. package/dist/render/slack/assets.d.ts.map +1 -0
  410. package/dist/render/slack/assets.js +40 -0
  411. package/dist/render/slack/assets.js.map +1 -0
  412. package/dist/render/slack/blocks.d.ts +72 -0
  413. package/dist/render/slack/blocks.d.ts.map +1 -0
  414. package/dist/render/slack/blocks.js +77 -0
  415. package/dist/render/slack/blocks.js.map +1 -0
  416. package/dist/render/slack/envelope.d.ts +52 -0
  417. package/dist/render/slack/envelope.d.ts.map +1 -0
  418. package/dist/render/slack/envelope.js +547 -0
  419. package/dist/render/slack/envelope.js.map +1 -0
  420. package/dist/render/slack/format.d.ts +70 -0
  421. package/dist/render/slack/format.d.ts.map +1 -0
  422. package/dist/render/slack/format.js +209 -0
  423. package/dist/render/slack/format.js.map +1 -0
  424. package/dist/render/slack/index.d.ts +6 -0
  425. package/dist/render/slack/index.d.ts.map +1 -0
  426. package/dist/render/slack/index.js +12 -0
  427. package/dist/render/slack/index.js.map +1 -0
  428. package/dist/render/slack/markdown_content.d.ts +17 -0
  429. package/dist/render/slack/markdown_content.d.ts.map +1 -0
  430. package/dist/render/slack/markdown_content.js +404 -0
  431. package/dist/render/slack/markdown_content.js.map +1 -0
  432. package/dist/render/text/envelope.d.ts +15 -0
  433. package/dist/render/text/envelope.d.ts.map +1 -0
  434. package/dist/render/text/envelope.js +17 -0
  435. package/dist/render/text/envelope.js.map +1 -0
  436. package/dist/render/text/index.d.ts +2 -0
  437. package/dist/render/text/index.d.ts.map +1 -0
  438. package/dist/render/text/index.js +8 -0
  439. package/dist/render/text/index.js.map +1 -0
  440. package/dist/testing/conformance.d.ts +145 -0
  441. package/dist/testing/conformance.d.ts.map +1 -0
  442. package/dist/testing/conformance.js +303 -0
  443. package/dist/testing/conformance.js.map +1 -0
  444. package/dist/testing/icon.d.ts +11 -0
  445. package/dist/testing/icon.d.ts.map +1 -0
  446. package/dist/testing/icon.js +244 -0
  447. package/dist/testing/icon.js.map +1 -0
  448. package/dist/testing/index.d.ts +4 -0
  449. package/dist/testing/index.d.ts.map +1 -0
  450. package/dist/testing/index.js +10 -0
  451. package/dist/testing/index.js.map +1 -0
  452. package/dist/testing/registration.d.ts +32 -0
  453. package/dist/testing/registration.d.ts.map +1 -0
  454. package/dist/testing/registration.js +105 -0
  455. package/dist/testing/registration.js.map +1 -0
  456. package/dist/validate/authoring_schema.d.ts +33 -0
  457. package/dist/validate/authoring_schema.d.ts.map +1 -0
  458. package/dist/validate/authoring_schema.js +306 -0
  459. package/dist/validate/authoring_schema.js.map +1 -0
  460. package/dist/validate/composition_schema.d.ts +80 -0
  461. package/dist/validate/composition_schema.d.ts.map +1 -0
  462. package/dist/validate/composition_schema.js +127 -0
  463. package/dist/validate/composition_schema.js.map +1 -0
  464. package/dist/validate/index.d.ts +9 -0
  465. package/dist/validate/index.d.ts.map +1 -0
  466. package/dist/validate/index.js +15 -0
  467. package/dist/validate/index.js.map +1 -0
  468. package/dist/validate/input_budget.d.ts +35 -0
  469. package/dist/validate/input_budget.d.ts.map +1 -0
  470. package/dist/validate/input_budget.js +151 -0
  471. package/dist/validate/input_budget.js.map +1 -0
  472. package/dist/validate/json_schema.d.ts +32 -0
  473. package/dist/validate/json_schema.d.ts.map +1 -0
  474. package/dist/validate/json_schema.js +68 -0
  475. package/dist/validate/json_schema.js.map +1 -0
  476. package/dist/validate/node_issues.d.ts +12 -0
  477. package/dist/validate/node_issues.d.ts.map +1 -0
  478. package/dist/validate/node_issues.js +61 -0
  479. package/dist/validate/node_issues.js.map +1 -0
  480. package/dist/validate/url.d.ts +50 -0
  481. package/dist/validate/url.d.ts.map +1 -0
  482. package/dist/validate/url.js +107 -0
  483. package/dist/validate/url.js.map +1 -0
  484. package/dist/validate/validation.d.ts +95 -0
  485. package/dist/validate/validation.d.ts.map +1 -0
  486. package/dist/validate/validation.js +157 -0
  487. package/dist/validate/validation.js.map +1 -0
  488. package/dist/validate/value_schemas.d.ts +53 -0
  489. package/dist/validate/value_schemas.d.ts.map +1 -0
  490. package/dist/validate/value_schemas.js +50 -0
  491. package/dist/validate/value_schemas.js.map +1 -0
  492. package/package.json +119 -5
@@ -0,0 +1,435 @@
1
+ import type { ReactNode } from 'react';
2
+ import { z, type ZodObject, type ZodType } from 'zod';
3
+ import type { ActionEventRef } from '../composition/action_event.js';
4
+ import { type ChildNodeRef, type SurfaceName } from '../composition/body_node_base.js';
5
+ import type { PrimitiveNode } from '../composition/node.js';
6
+ import type { ValidationError } from '../composition/validation_error.js';
7
+ import type { MarkdownContent } from './markdown_content.js';
8
+ import type { PrimitiveExample } from './primitive_example.js';
9
+ import type { PrimitiveIcon } from './primitive_icon.js';
10
+ import type { SlackAssetCollector } from './slack_assets.js';
11
+ import type { SlackBlock } from './slack_blocks.js';
12
+ export type { PrimitiveNode };
13
+ /**
14
+ * A primitive's entry in the catalog the authoring prompt is built from.
15
+ *
16
+ * Written for the model rather than for a developer: `useWhen` and `avoidWhen`
17
+ * are what steer it away from reaching for the wrong primitive. `name` is the
18
+ * one host-facing field, and the prompt never prints it.
19
+ */
20
+ export interface PrimitiveCatalogEntry {
21
+ type: string;
22
+ /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */
23
+ name?: string;
24
+ /** One line on what the primitive is for, in the model's voice. */
25
+ purpose: string;
26
+ /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */
27
+ useWhen: string[];
28
+ /** Situations that look like a fit but are not, naming the primitive to reach for instead. */
29
+ avoidWhen: string[];
30
+ /** A node literal the authoring prompt inlines under this primitive. */
31
+ example: unknown;
32
+ }
33
+ /** A style a renderer asks for by name, resolved to a class by the host's adapter. */
34
+ export interface StyleHandle {
35
+ /** Stable lookup key. The adapter's map is keyed on this. */
36
+ key: string;
37
+ /** Debug-facing label, which an adapter may fold into a generated class name. */
38
+ readableName: string;
39
+ }
40
+ /** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */
41
+ export type ThemeTokenPath = string;
42
+ /**
43
+ * The sdk's own render context, and {@link DefaultPackTypes.context}.
44
+ *
45
+ * A pack with real theme tokens or a richer style-handle type declares its
46
+ * own context in its {@link PackTypes}; {@link StyledRenderContext} is the
47
+ * sdk's own extension. The bag is what lets a pack narrow without
48
+ * re-declaring everything that mentions a context.
49
+ */
50
+ export interface PrimitiveRenderContext {
51
+ /**
52
+ * The progressive enhancements this render may assume, by id. A set rather
53
+ * than a field per feature so adding an enhancement costs no plumbing:
54
+ * containers forward the whole context, and a renderer asks
55
+ * `context.enhancements?.has('tableSort')`.
56
+ *
57
+ * Empty or absent is the baseline every host can render, so a renderer must
58
+ * still answer the question on its own. See `docs/rendering.md`.
59
+ */
60
+ enhancements?: ReadonlySet<string>;
61
+ /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */
62
+ anchors?: boolean;
63
+ /** Raises an interaction for the host to route. Absent means render non-interactively. */
64
+ onEvent?: (event: ActionEventRef) => void;
65
+ }
66
+ /**
67
+ * The render-context argument, optional only when omitting it is sound.
68
+ *
69
+ * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`
70
+ * is a complete value and a caller may leave it out. A pack that narrows the
71
+ * context with a required member makes the argument mandatory.
72
+ */
73
+ export type ReactContextArg<TContext> = Record<string, never> extends TContext ? [context?: TContext] : [context: TContext];
74
+ /**
75
+ * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter
76
+ * supplies. A pack that styles differently uses its own `TContext` instead.
77
+ */
78
+ export interface StyledRenderContext extends PrimitiveRenderContext {
79
+ /** Resolves handles to a `className`. Absent means the host supplies no styling. */
80
+ resolveClassName?: (...handles: StyleHandle[]) => string;
81
+ /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */
82
+ cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;
83
+ }
84
+ /** Passed to a primitive's style collector so it can vary CSS by layout mode. */
85
+ export interface PrimitiveStyleCollectionContext {
86
+ /** The render fills its container rather than sitting at a fixed width. */
87
+ fluid?: boolean;
88
+ }
89
+ /** A pack's collected styles, opaque to the SDK. */
90
+ export type PrimitiveStyleCollector = object;
91
+ /**
92
+ * The types a pack binds once and writes every primitive against: the palette
93
+ * its frames supply, the context its `react` renderers receive, the collector
94
+ * its `collectStyles` hooks mutate, and the Slack payload and collector types.
95
+ *
96
+ * Extend {@link DefaultPackTypes} and narrow only what the pack needs:
97
+ *
98
+ * ```ts
99
+ * interface SlidesPackTypes extends DefaultPackTypes {
100
+ * theme: SlideTheme;
101
+ * context: SlideRenderContext;
102
+ * }
103
+ * ```
104
+ */
105
+ export interface PackTypes {
106
+ theme: unknown;
107
+ context: unknown;
108
+ collector: PrimitiveStyleCollector;
109
+ slackBlock: unknown;
110
+ slackCollector: unknown;
111
+ }
112
+ /** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */
113
+ export interface DefaultPackTypes extends PackTypes {
114
+ theme: unknown;
115
+ context: PrimitiveRenderContext;
116
+ collector: PrimitiveStyleCollector;
117
+ slackBlock: SlackBlock;
118
+ slackCollector: SlackAssetCollector;
119
+ }
120
+ /**
121
+ * Each surface's renderer signature: the env bag it receives beyond the node,
122
+ * and what it returns.
123
+ *
124
+ * Written out per surface rather than derived through an indexed access. A bag
125
+ * is additive: a new extra on a surface is not an arity break. {@link Renderer}
126
+ * indexes this table for the dispatcher cast; {@link Renderers} does not.
127
+ */
128
+ export interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {
129
+ react: {
130
+ env: {
131
+ context: T['context'];
132
+ scope: RenderScope<T>;
133
+ /**
134
+ * The frame's resolved palette, when this render is reached through the
135
+ * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to
136
+ * resolve one from, so it is absent there — a pack that needs a
137
+ * literal color outside `snapshot` still goes through `context`.
138
+ */
139
+ theme?: T['theme'];
140
+ };
141
+ output: ReactNode;
142
+ };
143
+ /**
144
+ * Identical to `react`, and served by the same renderer: an image backend
145
+ * lays out the pack's DOM tree and stylesheet rather than a second tree
146
+ * authored for it. The surface stays separate so a node can be hidden from
147
+ * snapshots alone, and so a {@link Frame} has something to draw inside.
148
+ */
149
+ snapshot: {
150
+ env: {
151
+ context: T['context'];
152
+ scope: RenderScope<T>;
153
+ /** The frame's resolved palette for this render's mode; see `react.env.theme`. */
154
+ theme?: T['theme'];
155
+ };
156
+ output: ReactNode;
157
+ };
158
+ text: {
159
+ env: {
160
+ scope: RenderScope<T>;
161
+ };
162
+ output: string;
163
+ };
164
+ /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */
165
+ markdown: {
166
+ env: {
167
+ scope: RenderScope<T>;
168
+ };
169
+ output: MarkdownContent;
170
+ };
171
+ /**
172
+ * Returns one payload or several, so a primitive need not wrap a single
173
+ * payload in an array.
174
+ */
175
+ slack: {
176
+ env: {
177
+ collector?: T['slackCollector'];
178
+ scope: RenderScope<T>;
179
+ };
180
+ output: T['slackBlock'] | readonly T['slackBlock'][];
181
+ };
182
+ }
183
+ /**
184
+ * The dispatcher a renderer is given so a container can recurse into a child
185
+ * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous
186
+ * inventory has no single node type to name.
187
+ *
188
+ * Passed as `scope` on every renderer's env bag. The dispatcher's own named
189
+ * methods stay positional.
190
+ */
191
+ export interface RenderScope<T extends PackTypes = DefaultPackTypes> {
192
+ readonly definitions: readonly AnyPrimitiveDefinition[];
193
+ /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */
194
+ getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;
195
+ /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */
196
+ renderOn<S extends SurfaceName>(surface: S, node: PrimitiveNode, extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>): SurfaceMap<T>[S]['output'] | undefined;
197
+ renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;
198
+ collectStyles(node: PrimitiveNode, styles: PrimitiveStyleCollector, context: PrimitiveStyleCollectionContext): void;
199
+ renderText(node: PrimitiveNode): string;
200
+ renderMarkdown(node: PrimitiveNode): string;
201
+ /** A child as content, for a container building with `md`. */
202
+ renderMarkdownContent(node: PrimitiveNode): MarkdownContent;
203
+ /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */
204
+ renderSlack(node: PrimitiveNode, collector?: T['slackCollector']): readonly T['slackBlock'][];
205
+ /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */
206
+ estimateSnapshotHeight(node: PrimitiveNode): number;
207
+ /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */
208
+ validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;
209
+ }
210
+ /**
211
+ * One surface's renderer for one node type, per {@link SurfaceMap}.
212
+ *
213
+ * Indexes the env bag. Do not use this to type the renderers map: the
214
+ * written-out signatures on {@link Renderers} are what keep the bags checked
215
+ * per surface.
216
+ */
217
+ export type Renderer<TNode extends PrimitiveNode, S extends SurfaceName, T extends PackTypes = DefaultPackTypes> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];
218
+ /**
219
+ * The surface a pack may declare beyond the mandatory three.
220
+ *
221
+ * Only `slack`, and even that stays optional per primitive: the dispatcher
222
+ * converts the mandatory markdown to Block Kit, so a missing Slack renderer
223
+ * degrades rather than disappearing. `snapshot` is not here because no primitive
224
+ * implements it — the surface reuses `react`.
225
+ */
226
+ export declare const OPTIONAL_SURFACES: readonly ["slack"];
227
+ /** One of the {@link OPTIONAL_SURFACES}. */
228
+ export type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];
229
+ /**
230
+ * One renderer per surface a primitive implements.
231
+ *
232
+ * `react`, `text`, and `markdown` are always required: those three are what
233
+ * make "every composition degrades" true. `react` serves the `snapshot` surface
234
+ * too, so targeting images costs a primitive nothing.
235
+ *
236
+ * `slack` is declared method-style deliberately: method parameters are checked
237
+ * bivariantly, which is what lets a pack narrow the collector's node type.
238
+ */
239
+ export interface Renderers<TNode extends PrimitiveNode, T extends PackTypes = DefaultPackTypes> {
240
+ react(node: TNode, env: {
241
+ context: T['context'];
242
+ scope: RenderScope<T>;
243
+ /** See {@link SurfaceMap.react}'s `env.theme`. */
244
+ theme?: T['theme'];
245
+ }): ReactNode;
246
+ text(node: TNode, env: {
247
+ scope: RenderScope<T>;
248
+ }): string;
249
+ markdown(node: TNode, env: {
250
+ scope: RenderScope<T>;
251
+ }): MarkdownContent;
252
+ slack?(node: TNode, env: {
253
+ collector?: T['slackCollector'];
254
+ scope: RenderScope<T>;
255
+ }): T['slackBlock'] | readonly T['slackBlock'][];
256
+ }
257
+ /**
258
+ * Measurements a frame can ask of a node before drawing it.
259
+ *
260
+ * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so
261
+ * a frame that sums node heights sizes short.
262
+ */
263
+ export interface PrimitiveMetrics<TNode extends PrimitiveNode> {
264
+ /** The node's drawn height in pixels at the frame's width. */
265
+ snapshotHeight?: (node: TNode) => number;
266
+ }
267
+ /**
268
+ * Every primitive's schema is an object schema, because {@link definePrimitive}
269
+ * extends it with `id` and `surfaces` and the composition builds a
270
+ * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather
271
+ * than `ZodType<unknown>` so a union or intersection schema is a compile
272
+ * error at the definition, not a runtime failure at the first `.extend()`.
273
+ * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the
274
+ * refinement through `.extend()`, so top-level refinements are unaffected.
275
+ */
276
+ export type PrimitiveSchema = ZodObject;
277
+ /**
278
+ * The child-ref shape a primitive definition's own `children` returns.
279
+ *
280
+ * {@link ChildNodeRef} stays erased (`node: unknown`) because
281
+ * `createChildNodeWalker` mixes children from every primitive type in the
282
+ * runtime into one map and cannot name a single node type for them. A single
283
+ * definition has no such excuse: its `children` should not type-check
284
+ * against `unknown` and let something that is not a {@link PrimitiveNode} —
285
+ * `null`, for instance — silently disappear from every tree walk.
286
+ */
287
+ export interface PrimitiveChildRef extends ChildNodeRef {
288
+ node: PrimitiveNode;
289
+ }
290
+ /**
291
+ * One primitive: its node type, schema, catalog entry, and a renderer per
292
+ * surface. The unit of vocabulary, and what {@link definePrimitive} takes.
293
+ *
294
+ * `T` is the pack's {@link PackTypes}, bound once with
295
+ * {@link definePrimitiveFor} so each primitive names only `TNode`.
296
+ */
297
+ export interface PrimitiveDefinition<TNode extends PrimitiveNode, T extends PackTypes = DefaultPackTypes, TSchema extends PrimitiveSchema = PrimitiveSchema> {
298
+ /** The node's discriminant, and the key this primitive occupies in an inventory. */
299
+ type: TNode['type'];
300
+ /** How the authoring prompt describes this primitive to the model. */
301
+ catalog: PrimitiveCatalogEntry;
302
+ /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */
303
+ icon?: PrimitiveIcon;
304
+ /**
305
+ * Driven by the conformance harness, bare or named; read them with
306
+ * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the
307
+ * prompt shows.
308
+ */
309
+ examples: readonly (TNode | PrimitiveExample<TNode>)[];
310
+ /**
311
+ * This primitive on its own. A container declares
312
+ * {@link PrimitiveDefinition.schemaFor} as well, and uses
313
+ * {@link unresolvedBodyNodeSchema} in the child slot here.
314
+ */
315
+ schema: TSchema;
316
+ /**
317
+ * A container's schema, bound to the body-node union of the composition it is
318
+ * being built into.
319
+ *
320
+ * Declaring the shape and letting each composition supply its own union is
321
+ * what lets one primitive appear in two runtimes with different inventories:
322
+ * `z.lazy` memoizes per instance, and an instance built here belongs to
323
+ * exactly one union.
324
+ */
325
+ schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;
326
+ /** One function per surface; `react` serves `snapshot` as well. */
327
+ renderers: Renderers<TNode, T>;
328
+ /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */
329
+ metrics?: PrimitiveMetrics<TNode>;
330
+ /**
331
+ * Render-time URL trust, the second of the two layers in `validate/url.ts`.
332
+ *
333
+ * Returning `null` drops the node. Applied even to an unvalidated node, so a
334
+ * renderer invoked directly still cannot emit an unsafe URL.
335
+ */
336
+ sanitize?: (node: TNode) => TNode | null;
337
+ /**
338
+ * Nested nodes, for containers, in the order the `react` renderer draws
339
+ * them; `findNodeElementPairs` relies on it. Absent means a leaf.
340
+ */
341
+ children?: (node: TNode) => readonly PrimitiveChildRef[];
342
+ /**
343
+ * True when this node produces surface output of its own, not only via
344
+ * {@link PrimitiveDefinition.children}. A non-empty `children` result is
345
+ * otherwise the complete source of rendered content, so a hybrid container
346
+ * that still owns string fields returns true to keep rendering when every
347
+ * nested node is hidden from the surface.
348
+ */
349
+ hasOwnContent?: (node: TNode) => boolean;
350
+ /** Contributes this node's CSS by mutating `styles`, once per node per render. */
351
+ collectStyles?: (node: TNode, env: {
352
+ styles: T['collector'];
353
+ context: PrimitiveStyleCollectionContext;
354
+ }) => void;
355
+ }
356
+ /**
357
+ * {@link PrimitiveDefinition} with every type parameter erased, and the form an
358
+ * inventory is stored in.
359
+ *
360
+ * A heterogeneous pack has no single `TNode` to be generic over, so the
361
+ * renderers degrade to `unknown` here.
362
+ *
363
+ * Each field carries the same contract as its {@link PrimitiveDefinition}
364
+ * counterpart; only the types are erased.
365
+ */
366
+ export interface AnyPrimitiveDefinition {
367
+ type: string;
368
+ catalog: PrimitiveCatalogEntry;
369
+ icon?: PrimitiveIcon;
370
+ examples: readonly (PrimitiveNode | PrimitiveExample)[];
371
+ schema: PrimitiveSchema;
372
+ schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;
373
+ renderers: Record<'react' | 'text' | 'markdown', unknown> & Partial<Record<'slack', unknown>>;
374
+ metrics?: {
375
+ snapshotHeight?: unknown;
376
+ };
377
+ sanitize?: unknown;
378
+ children?: unknown;
379
+ hasOwnContent?: unknown;
380
+ collectStyles?: unknown;
381
+ }
382
+ /** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */
383
+ export declare const validateWithSchema: (schema: PrimitiveSchema, node: unknown, path: string, errors: ValidationError[]) => void;
384
+ /** The `id` every node may carry, unique within a composition. */
385
+ export declare const bodyNodeIdSchema: z.ZodString;
386
+ /** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */
387
+ export declare const bodyNodeSurfacesSchema: z.ZodArray<z.ZodEnum<{
388
+ react: "react";
389
+ snapshot: "snapshot";
390
+ text: "text";
391
+ markdown: "markdown";
392
+ slack: "slack";
393
+ }>>;
394
+ /**
395
+ * The child slot in a container's standalone {@link PrimitiveDefinition.schema},
396
+ * where no body-node union is available.
397
+ *
398
+ * Deliberately permissive rather than `z.unknown()`: it still rejects a child
399
+ * that is not a node at all, which is the error worth catching without an
400
+ * inventory. Anything that depends on *which* types are legal — the validator,
401
+ * the parser, the JSON Schema projection — goes through
402
+ * {@link PrimitiveDefinition.schemaFor} and sees the real union.
403
+ */
404
+ export declare const unresolvedBodyNodeSchema: z.ZodObject<{
405
+ type: z.ZodString;
406
+ }, z.core.$loose>;
407
+ /**
408
+ * Declares one primitive, extending its schema with the `id` and `surfaces`
409
+ * fields every node carries, and closing it to unknown keys so a node is held
410
+ * to the same rule as the composition root and the JSON Schema an agent reads.
411
+ * A schema with its own catchall (`z.looseObject`) keeps it.
412
+ *
413
+ * A pack normally calls the form {@link definePrimitiveFor} binds to its own
414
+ * {@link PackTypes}, so each primitive names only `TNode`.
415
+ */
416
+ export declare const definePrimitive: <TNode extends PrimitiveNode, T extends PackTypes = DefaultPackTypes, TSchema extends PrimitiveSchema = PrimitiveSchema>(definition: PrimitiveDefinition<TNode, T, TSchema>) => PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>>;
417
+ /**
418
+ * {@link definePrimitive} bound to one pack's {@link PackTypes}.
419
+ *
420
+ * ```ts
421
+ * const define = definePrimitiveFor<SlidesPackTypes>();
422
+ * export const note = define({ type: 'note', … });
423
+ * ```
424
+ */
425
+ export declare const definePrimitiveFor: <T extends PackTypes>() => <TNode extends PrimitiveNode, TSchema extends PrimitiveSchema = PrimitiveSchema>(definition: PrimitiveDefinition<TNode, T, TSchema>) => PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>>;
426
+ /**
427
+ * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the
428
+ * return type is rebuilt from `TSchema`'s shape. The brand on a field schema
429
+ * stays on that same object at runtime.
430
+ */
431
+ export type WithNodeFields<TSchema extends PrimitiveSchema> = TSchema extends ZodObject<infer Shape> ? ZodObject<Shape & {
432
+ id: ReturnType<typeof bodyNodeIdSchema.optional>;
433
+ surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;
434
+ }> : PrimitiveSchema;
435
+ //# sourceMappingURL=primitive_module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive_module.d.ts","sourceRoot":"","sources":["../../src/define/primitive_module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,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AO,SAAS,eAAe,GAAG,eAAe,EAEjD,YAAY,mBAAmB,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,KACjD,mBAAmB,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CACR,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,eAAe,IACxD,OAAO,SAAS,SAAS,CAAC,MAAM,KAAK,CAAC,GAClC,SAAS,CACP,KAAK,GAAG;IACN,EAAE,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACjD,QAAQ,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,QAAQ,CAAC,CAAC;CAC9D,CACF,GACD,eAAe,CAAC"}
@@ -0,0 +1,112 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { z } from 'zod';
8
+ import { SURFACE_NAMES, } from '../composition/body_node_base.js';
9
+ import { ISOMER_ERROR_CODES, IsomerError } from '../composition/error.js';
10
+ import { formatZodIssues, oneOf } from './zod_format.js';
11
+ import { requiredString } from './zod_helpers.js';
12
+ /**
13
+ * The surface a pack may declare beyond the mandatory three.
14
+ *
15
+ * Only `slack`, and even that stays optional per primitive: the dispatcher
16
+ * converts the mandatory markdown to Block Kit, so a missing Slack renderer
17
+ * degrades rather than disappearing. `snapshot` is not here because no primitive
18
+ * implements it — the surface reuses `react`.
19
+ */
20
+ export const OPTIONAL_SURFACES = [
21
+ 'slack',
22
+ ];
23
+ /** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */
24
+ export const validateWithSchema = (schema, node, path, errors) => {
25
+ const result = schema.safeParse(node, { reportInput: true });
26
+ if (!result.success) {
27
+ errors.push(...formatZodIssues(result.error.issues, path));
28
+ }
29
+ };
30
+ /** The `id` every node may carry, unique within a composition. */
31
+ export const bodyNodeIdSchema = requiredString('must be a non-empty string');
32
+ /** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */
33
+ export const bodyNodeSurfacesSchema = z
34
+ .array(z.enum(SURFACE_NAMES, {
35
+ error: () => oneOf(SURFACE_NAMES),
36
+ }))
37
+ .min(1, { error: 'must contain at least one surface' });
38
+ /**
39
+ * The child slot in a container's standalone {@link PrimitiveDefinition.schema},
40
+ * where no body-node union is available.
41
+ *
42
+ * Deliberately permissive rather than `z.unknown()`: it still rejects a child
43
+ * that is not a node at all, which is the error worth catching without an
44
+ * inventory. Anything that depends on *which* types are legal — the validator,
45
+ * the parser, the JSON Schema projection — goes through
46
+ * {@link PrimitiveDefinition.schemaFor} and sees the real union.
47
+ */
48
+ export const unresolvedBodyNodeSchema = z.looseObject({
49
+ type: requiredString('must be a non-empty string'),
50
+ });
51
+ /**
52
+ * Declares one primitive, extending its schema with the `id` and `surfaces`
53
+ * fields every node carries, and closing it to unknown keys so a node is held
54
+ * to the same rule as the composition root and the JSON Schema an agent reads.
55
+ * A schema with its own catchall (`z.looseObject`) keeps it.
56
+ *
57
+ * A pack normally calls the form {@link definePrimitiveFor} binds to its own
58
+ * {@link PackTypes}, so each primitive names only `TNode`.
59
+ */
60
+ export const definePrimitive = (definition) => {
61
+ const { schemaFor } = definition;
62
+ return {
63
+ ...definition,
64
+ schema: withNodeFields(definition.schema),
65
+ // Both forms get the node fields, or a container would accept `id` and
66
+ // `surfaces` standalone and reject them inside a composition.
67
+ ...(schemaFor
68
+ ? {
69
+ schemaFor: (bodyNodeSchema) => withNodeFields(schemaFor(bodyNodeSchema)),
70
+ }
71
+ : {}),
72
+ };
73
+ };
74
+ /**
75
+ * {@link definePrimitive} bound to one pack's {@link PackTypes}.
76
+ *
77
+ * ```ts
78
+ * const define = definePrimitiveFor<SlidesPackTypes>();
79
+ * export const note = define({ type: 'note', … });
80
+ * ```
81
+ */
82
+ export const definePrimitiveFor = () => (definition) => definePrimitive(definition);
83
+ // Marks the field schemas `definePrimitive` adds. A schema derived from a
84
+ // defined one shares them by reference, and `Symbol.for` matches across ESM and
85
+ // CommonJS copies of the SDK.
86
+ const NODE_FIELD = Symbol.for('elastic.isomer.node_field');
87
+ const nodeField = (schema) => Object.defineProperty(schema, NODE_FIELD, { value: true });
88
+ const NODE_FIELDS = {
89
+ id: nodeField(bodyNodeIdSchema.optional()),
90
+ surfaces: nodeField(bodyNodeSurfacesSchema.optional()),
91
+ };
92
+ const isNodeField = (schema) => {
93
+ let current = schema;
94
+ while (current && typeof current === 'object') {
95
+ if (Object.hasOwn(current, NODE_FIELD))
96
+ return true;
97
+ const { def } = current;
98
+ if (def?.type !== 'optional')
99
+ return false;
100
+ current = def.innerType;
101
+ }
102
+ return false;
103
+ };
104
+ const withNodeFields = (schema) => {
105
+ const reserved = Object.keys(NODE_FIELDS).find((field) => Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field]));
106
+ if (reserved) {
107
+ throw new IsomerError(ISOMER_ERROR_CODES.RESERVED_NODE_FIELD, `definePrimitive: a primitive schema cannot declare \`${reserved}\`; every body node has it.`);
108
+ }
109
+ const extended = schema.extend(NODE_FIELDS);
110
+ return (schema.def.catchall === undefined ? extended.strict() : extended);
111
+ };
112
+ //# sourceMappingURL=primitive_module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive_module.js","sourceRoot":"","sources":["../../src/define/primitive_module.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAgC,MAAM,KAAK,CAAC;AAGtD,OAAO,EAEL,aAAa,GAEd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASvE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgP/C;;;;;;;GAOG;AACH,MAA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AAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CACR,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAC1E,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,WAAW,CACnB,kBAAkB,CAAC,mBAAmB,EACtC,wDAAwD,QAAQ,6BAA6B,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CACtC,CAAC;AAC/B,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport type { ReactNode } from 'react';\nimport { z, type ZodObject, type ZodType } from 'zod';\n\nimport type { ActionEventRef } from '../composition/action_event';\nimport {\n type ChildNodeRef,\n SURFACE_NAMES,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport { ISOMER_ERROR_CODES, IsomerError } from '../composition/error';\nimport type { PrimitiveNode } from '../composition/node';\nimport type { ValidationError } from '../composition/validation_error';\n\nimport type { MarkdownContent } from './markdown_content';\nimport type { PrimitiveExample } from './primitive_example';\nimport type { PrimitiveIcon } from './primitive_icon';\nimport type { SlackAssetCollector } from './slack_assets';\nimport type { SlackBlock } from './slack_blocks';\nimport { formatZodIssues, oneOf } from './zod_format';\nimport { requiredString } from './zod_helpers';\n\nexport type { PrimitiveNode };\n\n/**\n * A primitive's entry in the catalog the authoring prompt is built from.\n *\n * Written for the model rather than for a developer: `useWhen` and `avoidWhen`\n * are what steer it away from reaching for the wrong primitive. `name` is the\n * one host-facing field, and the prompt never prints it.\n */\nexport interface PrimitiveCatalogEntry {\n type: string;\n /** Short name a host shows for the primitive, e.g. `Stat group`. Absent means the host derives one from `type`. */\n name?: string;\n /** One line on what the primitive is for, in the model's voice. */\n purpose: string;\n /** Situations that call for this primitive. Phrase each as a user intent, not a shape. */\n useWhen: string[];\n /** Situations that look like a fit but are not, naming the primitive to reach for instead. */\n avoidWhen: string[];\n /** A node literal the authoring prompt inlines under this primitive. */\n example: unknown;\n}\n\n/** A style a renderer asks for by name, resolved to a class by the host's adapter. */\nexport interface StyleHandle {\n /** Stable lookup key. The adapter's map is keyed on this. */\n key: string;\n /** Debug-facing label, which an adapter may fold into a generated class name. */\n readableName: string;\n}\n\n/** Dotted path into a pack's theme tokens, e.g. `colors.text.subdued`. */\nexport type ThemeTokenPath = string;\n\n/**\n * The sdk's own render context, and {@link DefaultPackTypes.context}.\n *\n * A pack with real theme tokens or a richer style-handle type declares its\n * own context in its {@link PackTypes}; {@link StyledRenderContext} is the\n * sdk's own extension. The bag is what lets a pack narrow without\n * re-declaring everything that mentions a context.\n */\nexport interface PrimitiveRenderContext {\n /**\n * The progressive enhancements this render may assume, by id. A set rather\n * than a field per feature so adding an enhancement costs no plumbing:\n * containers forward the whole context, and a renderer asks\n * `context.enhancements?.has('tableSort')`.\n *\n * Empty or absent is the baseline every host can render, so a renderer must\n * still answer the question on its own. See `docs/rendering.md`.\n */\n enhancements?: ReadonlySet<string>;\n /** Turns on `nodeAnchor` outside an HTML surface render, on the React and `snapshot` surfaces; inside one, the surface decides. */\n anchors?: boolean;\n /** Raises an interaction for the host to route. Absent means render non-interactively. */\n onEvent?: (event: ActionEventRef) => void;\n}\n\n/**\n * The render-context argument, optional only when omitting it is sound.\n *\n * The sdk's own {@link PrimitiveRenderContext} has no required field, so `{}`\n * is a complete value and a caller may leave it out. A pack that narrows the\n * context with a required member makes the argument mandatory.\n */\nexport type ReactContextArg<TContext> =\n Record<string, never> extends TContext\n ? [context?: TContext]\n : [context: TContext];\n\n/**\n * {@link PrimitiveRenderContext} plus the CSS-in-JS hooks an HTML style adapter\n * supplies. A pack that styles differently uses its own `TContext` instead.\n */\nexport interface StyledRenderContext extends PrimitiveRenderContext {\n /** Resolves handles to a `className`. Absent means the host supplies no styling. */\n resolveClassName?: (...handles: StyleHandle[]) => string;\n /** Resolves a theme token to a CSS variable reference. Absent means inline the literal value. */\n cssVarRef?: (path: ThemeTokenPath) => `var(--${string})`;\n}\n\n/** Passed to a primitive's style collector so it can vary CSS by layout mode. */\nexport interface PrimitiveStyleCollectionContext {\n /** The render fills its container rather than sitting at a fixed width. */\n fluid?: boolean;\n}\n\n/** A pack's collected styles, opaque to the SDK. */\nexport type PrimitiveStyleCollector = object;\n\n/**\n * The types a pack binds once and writes every primitive against: the palette\n * its frames supply, the context its `react` renderers receive, the collector\n * its `collectStyles` hooks mutate, and the Slack payload and collector types.\n *\n * Extend {@link DefaultPackTypes} and narrow only what the pack needs:\n *\n * ```ts\n * interface SlidesPackTypes extends DefaultPackTypes {\n * theme: SlideTheme;\n * context: SlideRenderContext;\n * }\n * ```\n */\nexport interface PackTypes {\n theme: unknown;\n context: unknown;\n collector: PrimitiveStyleCollector;\n slackBlock: unknown;\n slackCollector: unknown;\n}\n\n/** {@link PackTypes} as the sdk itself binds them, and the default everywhere. */\nexport interface DefaultPackTypes extends PackTypes {\n theme: unknown;\n context: PrimitiveRenderContext;\n collector: PrimitiveStyleCollector;\n slackBlock: SlackBlock;\n slackCollector: SlackAssetCollector;\n}\n\n/**\n * Each surface's renderer signature: the env bag it receives beyond the node,\n * and what it returns.\n *\n * Written out per surface rather than derived through an indexed access. A bag\n * is additive: a new extra on a surface is not an arity break. {@link Renderer}\n * indexes this table for the dispatcher cast; {@link Renderers} does not.\n */\nexport interface SurfaceMap<T extends PackTypes = DefaultPackTypes> {\n react: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /**\n * The frame's resolved palette, when this render is reached through the\n * `snapshot` surface. A bare `react`/`html` render has no {@link Frame} to\n * resolve one from, so it is absent there — a pack that needs a\n * literal color outside `snapshot` still goes through `context`.\n */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n /**\n * Identical to `react`, and served by the same renderer: an image backend\n * lays out the pack's DOM tree and stylesheet rather than a second tree\n * authored for it. The surface stays separate so a node can be hidden from\n * snapshots alone, and so a {@link Frame} has something to draw inside.\n */\n snapshot: {\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** The frame's resolved palette for this render's mode; see `react.env.theme`. */\n theme?: T['theme'];\n };\n output: ReactNode;\n };\n text: {\n env: {\n scope: RenderScope<T>;\n };\n output: string;\n };\n /** Content built with `md`, escaped where it lands; authored Markdown source goes through `md.authored`. */\n markdown: {\n env: {\n scope: RenderScope<T>;\n };\n output: MarkdownContent;\n };\n /**\n * Returns one payload or several, so a primitive need not wrap a single\n * payload in an array.\n */\n slack: {\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n };\n output: T['slackBlock'] | readonly T['slackBlock'][];\n };\n}\n\n/**\n * The dispatcher a renderer is given so a container can recurse into a child\n * owned by another pack. Erased to {@link PrimitiveNode}: a heterogeneous\n * inventory has no single node type to name.\n *\n * Passed as `scope` on every renderer's env bag. The dispatcher's own named\n * methods stay positional.\n */\nexport interface RenderScope<T extends PackTypes = DefaultPackTypes> {\n readonly definitions: readonly AnyPrimitiveDefinition[];\n /** Throws for an unknown node type; a missing primitive is a bug, not a degradation. */\n getDefinition(node: PrimitiveNode): AnyPrimitiveDefinition;\n /** `undefined` when the node is hidden from `surface`, `sanitize` drops it, or its primitive declares no renderer for `surface`. */\n renderOn<S extends SurfaceName>(\n surface: S,\n node: PrimitiveNode,\n extras: Omit<SurfaceMap<T>[S]['env'], 'scope'>\n ): SurfaceMap<T>[S]['output'] | undefined;\n renderReact(node: PrimitiveNode, context?: T['context']): ReactNode;\n collectStyles(\n node: PrimitiveNode,\n styles: PrimitiveStyleCollector,\n context: PrimitiveStyleCollectionContext\n ): void;\n renderText(node: PrimitiveNode): string;\n renderMarkdown(node: PrimitiveNode): string;\n /** A child as content, for a container building with `md`. */\n renderMarkdownContent(node: PrimitiveNode): MarkdownContent;\n /** Empty when the node is hidden from `slack`, `sanitize` drops it, or its renderer returns nothing; a node with no `slack` renderer degrades through its markdown. */\n renderSlack(\n node: PrimitiveNode,\n collector?: T['slackCollector']\n ): readonly T['slackBlock'][];\n /** `0` when the node is hidden from `snapshot` or its primitive declares no `metrics.snapshotHeight`. */\n estimateSnapshotHeight(node: PrimitiveNode): number;\n /** Appends schema failures under `path` to `errors`, each naming `node`'s type. */\n validate(node: PrimitiveNode, path: string, errors: ValidationError[]): void;\n}\n\n/**\n * One surface's renderer for one node type, per {@link SurfaceMap}.\n *\n * Indexes the env bag. Do not use this to type the renderers map: the\n * written-out signatures on {@link Renderers} are what keep the bags checked\n * per surface.\n */\nexport type Renderer<\n TNode extends PrimitiveNode,\n S extends SurfaceName,\n T extends PackTypes = DefaultPackTypes,\n> = (node: TNode, env: SurfaceMap<T>[S]['env']) => SurfaceMap<T>[S]['output'];\n\n/**\n * The surface a pack may declare beyond the mandatory three.\n *\n * Only `slack`, and even that stays optional per primitive: the dispatcher\n * converts the mandatory markdown to Block Kit, so a missing Slack renderer\n * degrades rather than disappearing. `snapshot` is not here because no primitive\n * implements it — the surface reuses `react`.\n */\nexport const OPTIONAL_SURFACES = [\n 'slack',\n] as const satisfies readonly SurfaceName[];\n\n/** One of the {@link OPTIONAL_SURFACES}. */\nexport type OptionalSurface = (typeof OPTIONAL_SURFACES)[number];\n\n/**\n * One renderer per surface a primitive implements.\n *\n * `react`, `text`, and `markdown` are always required: those three are what\n * make \"every composition degrades\" true. `react` serves the `snapshot` surface\n * too, so targeting images costs a primitive nothing.\n *\n * `slack` is declared method-style deliberately: method parameters are checked\n * bivariantly, which is what lets a pack narrow the collector's node type.\n */\nexport interface Renderers<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n> {\n react(\n node: TNode,\n env: {\n context: T['context'];\n scope: RenderScope<T>;\n /** See {@link SurfaceMap.react}'s `env.theme`. */\n theme?: T['theme'];\n }\n ): ReactNode;\n text(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): string;\n markdown(\n node: TNode,\n env: {\n scope: RenderScope<T>;\n }\n ): MarkdownContent;\n slack?(\n node: TNode,\n env: {\n collector?: T['slackCollector'];\n scope: RenderScope<T>;\n }\n ): T['slackBlock'] | readonly T['slackBlock'][];\n}\n\n/**\n * Measurements a frame can ask of a node before drawing it.\n *\n * `snapshotHeight` is optional. The height estimate is `0` when it is missing, so\n * a frame that sums node heights sizes short.\n */\nexport interface PrimitiveMetrics<TNode extends PrimitiveNode> {\n /** The node's drawn height in pixels at the frame's width. */\n snapshotHeight?: (node: TNode) => number;\n}\n\n/**\n * Every primitive's schema is an object schema, because {@link definePrimitive}\n * extends it with `id` and `surfaces` and the composition builds a\n * `z.discriminatedUnion('type', …)` over them. Typed as `ZodObject` rather\n * than `ZodType<unknown>` so a union or intersection schema is a compile\n * error at the definition, not a runtime failure at the first `.extend()`.\n * Zod 4 types `z.object().superRefine(…)` as a `ZodObject` and preserves the\n * refinement through `.extend()`, so top-level refinements are unaffected.\n */\nexport type PrimitiveSchema = ZodObject;\n\n/**\n * The child-ref shape a primitive definition's own `children` returns.\n *\n * {@link ChildNodeRef} stays erased (`node: unknown`) because\n * `createChildNodeWalker` mixes children from every primitive type in the\n * runtime into one map and cannot name a single node type for them. A single\n * definition has no such excuse: its `children` should not type-check\n * against `unknown` and let something that is not a {@link PrimitiveNode} —\n * `null`, for instance — silently disappear from every tree walk.\n */\nexport interface PrimitiveChildRef extends ChildNodeRef {\n node: PrimitiveNode;\n}\n\n/**\n * One primitive: its node type, schema, catalog entry, and a renderer per\n * surface. The unit of vocabulary, and what {@link definePrimitive} takes.\n *\n * `T` is the pack's {@link PackTypes}, bound once with\n * {@link definePrimitiveFor} so each primitive names only `TNode`.\n */\nexport interface PrimitiveDefinition<\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n> {\n /** The node's discriminant, and the key this primitive occupies in an inventory. */\n type: TNode['type'];\n /** How the authoring prompt describes this primitive to the model. */\n catalog: PrimitiveCatalogEntry;\n /** Host-facing glyph, never shown to the model. Absent means the host supplies its own. */\n icon?: PrimitiveIcon;\n /**\n * Driven by the conformance harness, bare or named; read them with\n * `exampleNodes` or `primitiveExamples`. The catalog `example` is what the\n * prompt shows.\n */\n examples: readonly (TNode | PrimitiveExample<TNode>)[];\n /**\n * This primitive on its own. A container declares\n * {@link PrimitiveDefinition.schemaFor} as well, and uses\n * {@link unresolvedBodyNodeSchema} in the child slot here.\n */\n schema: TSchema;\n /**\n * A container's schema, bound to the body-node union of the composition it is\n * being built into.\n *\n * Declaring the shape and letting each composition supply its own union is\n * what lets one primitive appear in two runtimes with different inventories:\n * `z.lazy` memoizes per instance, and an instance built here belongs to\n * exactly one union.\n */\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n /** One function per surface; `react` serves `snapshot` as well. */\n renderers: Renderers<TNode, T>;\n /** Sizing a frame can ask for before drawing. Absent means it cannot be measured. */\n metrics?: PrimitiveMetrics<TNode>;\n /**\n * Render-time URL trust, the second of the two layers in `validate/url.ts`.\n *\n * Returning `null` drops the node. Applied even to an unvalidated node, so a\n * renderer invoked directly still cannot emit an unsafe URL.\n */\n sanitize?: (node: TNode) => TNode | null;\n /**\n * Nested nodes, for containers, in the order the `react` renderer draws\n * them; `findNodeElementPairs` relies on it. Absent means a leaf.\n */\n children?: (node: TNode) => readonly PrimitiveChildRef[];\n /**\n * True when this node produces surface output of its own, not only via\n * {@link PrimitiveDefinition.children}. A non-empty `children` result is\n * otherwise the complete source of rendered content, so a hybrid container\n * that still owns string fields returns true to keep rendering when every\n * nested node is hidden from the surface.\n */\n hasOwnContent?: (node: TNode) => boolean;\n /** Contributes this node's CSS by mutating `styles`, once per node per render. */\n collectStyles?: (\n node: TNode,\n env: { styles: T['collector']; context: PrimitiveStyleCollectionContext }\n ) => void;\n}\n\n/**\n * {@link PrimitiveDefinition} with every type parameter erased, and the form an\n * inventory is stored in.\n *\n * A heterogeneous pack has no single `TNode` to be generic over, so the\n * renderers degrade to `unknown` here.\n *\n * Each field carries the same contract as its {@link PrimitiveDefinition}\n * counterpart; only the types are erased.\n */\nexport interface AnyPrimitiveDefinition {\n type: string;\n catalog: PrimitiveCatalogEntry;\n icon?: PrimitiveIcon;\n examples: readonly (PrimitiveNode | PrimitiveExample)[];\n schema: PrimitiveSchema;\n schemaFor?: (bodyNodeSchema: ZodType<unknown>) => PrimitiveSchema;\n renderers: Record<'react' | 'text' | 'markdown', unknown> &\n Partial<Record<'slack', unknown>>;\n metrics?: {\n snapshotHeight?: unknown;\n };\n sanitize?: unknown;\n children?: unknown;\n hasOwnContent?: unknown;\n collectStyles?: unknown;\n}\n\n/** Parses `node` against `schema`, appending path-prefixed messages to `errors`. */\nexport const validateWithSchema = (\n schema: PrimitiveSchema,\n node: unknown,\n path: string,\n errors: ValidationError[]\n): void => {\n const result = schema.safeParse(node, { reportInput: true });\n if (!result.success) {\n errors.push(...formatZodIssues(result.error.issues, path));\n }\n};\n\n/** The `id` every node may carry, unique within a composition. */\nexport const bodyNodeIdSchema = requiredString('must be a non-empty string');\n\n/** The `surfaces` allowlist on a node. Absent means every surface; empty is rejected. */\nexport const bodyNodeSurfacesSchema = z\n .array(\n z.enum(SURFACE_NAMES, {\n error: () => oneOf(SURFACE_NAMES),\n })\n )\n .min(1, { error: 'must contain at least one surface' });\n\n/**\n * The child slot in a container's standalone {@link PrimitiveDefinition.schema},\n * where no body-node union is available.\n *\n * Deliberately permissive rather than `z.unknown()`: it still rejects a child\n * that is not a node at all, which is the error worth catching without an\n * inventory. Anything that depends on *which* types are legal — the validator,\n * the parser, the JSON Schema projection — goes through\n * {@link PrimitiveDefinition.schemaFor} and sees the real union.\n */\nexport const unresolvedBodyNodeSchema = z.looseObject({\n type: requiredString('must be a non-empty string'),\n});\n\n/**\n * Declares one primitive, extending its schema with the `id` and `surfaces`\n * fields every node carries, and closing it to unknown keys so a node is held\n * to the same rule as the composition root and the JSON Schema an agent reads.\n * A schema with its own catchall (`z.looseObject`) keeps it.\n *\n * A pack normally calls the form {@link definePrimitiveFor} binds to its own\n * {@link PackTypes}, so each primitive names only `TNode`.\n */\nexport const definePrimitive = <\n TNode extends PrimitiveNode,\n T extends PackTypes = DefaultPackTypes,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n>(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> => {\n const { schemaFor } = definition;\n return {\n ...definition,\n schema: withNodeFields(definition.schema),\n // Both forms get the node fields, or a container would accept `id` and\n // `surfaces` standalone and reject them inside a composition.\n ...(schemaFor\n ? {\n schemaFor: (bodyNodeSchema: ZodType<unknown>) =>\n withNodeFields(schemaFor(bodyNodeSchema)),\n }\n : {}),\n };\n};\n\n/**\n * {@link definePrimitive} bound to one pack's {@link PackTypes}.\n *\n * ```ts\n * const define = definePrimitiveFor<SlidesPackTypes>();\n * export const note = define({ type: 'note', … });\n * ```\n */\nexport const definePrimitiveFor =\n <T extends PackTypes>() =>\n <\n TNode extends PrimitiveNode,\n TSchema extends PrimitiveSchema = PrimitiveSchema,\n >(\n definition: PrimitiveDefinition<TNode, T, TSchema>\n ): PrimitiveDefinition<TNode, T, WithNodeFields<TSchema>> =>\n definePrimitive<TNode, T, TSchema>(definition);\n\n/**\n * `.extend()` on a generic `ZodObject` widens the shape to `any`, so the\n * return type is rebuilt from `TSchema`'s shape. The brand on a field schema\n * stays on that same object at runtime.\n */\nexport type WithNodeFields<TSchema extends PrimitiveSchema> =\n TSchema extends ZodObject<infer Shape>\n ? ZodObject<\n Shape & {\n id: ReturnType<typeof bodyNodeIdSchema.optional>;\n surfaces: ReturnType<typeof bodyNodeSurfacesSchema.optional>;\n }\n >\n : PrimitiveSchema;\n\n// Marks the field schemas `definePrimitive` adds. A schema derived from a\n// defined one shares them by reference, and `Symbol.for` matches across ESM and\n// CommonJS copies of the SDK.\nconst NODE_FIELD = Symbol.for('elastic.isomer.node_field');\n\nconst nodeField = <T extends ZodType>(schema: T): T =>\n Object.defineProperty(schema, NODE_FIELD, { value: true });\n\nconst NODE_FIELDS = {\n id: nodeField(bodyNodeIdSchema.optional()),\n surfaces: nodeField(bodyNodeSurfacesSchema.optional()),\n};\n\nconst isNodeField = (schema: unknown): boolean => {\n let current = schema;\n while (current && typeof current === 'object') {\n if (Object.hasOwn(current, NODE_FIELD)) return true;\n const { def } = current as {\n def?: { type?: string; innerType?: unknown };\n };\n if (def?.type !== 'optional') return false;\n current = def.innerType;\n }\n return false;\n};\n\nconst withNodeFields = <TSchema extends PrimitiveSchema>(\n schema: TSchema\n): WithNodeFields<TSchema> => {\n const reserved = Object.keys(NODE_FIELDS).find(\n (field) =>\n Object.hasOwn(schema.shape, field) && !isNodeField(schema.shape[field])\n );\n if (reserved) {\n throw new IsomerError(\n ISOMER_ERROR_CODES.RESERVED_NODE_FIELD,\n `definePrimitive: a primitive schema cannot declare \\`${reserved}\\`; every body node has it.`\n );\n }\n const extended = schema.extend(NODE_FIELDS);\n return (\n schema.def.catchall === undefined ? extended.strict() : extended\n ) as WithNodeFields<TSchema>;\n};\n"]}
@@ -0,0 +1,28 @@
1
+ import type { PrimitiveNode } from '../composition/node.js';
2
+ /**
3
+ * One image the host must upload before the message can be posted.
4
+ *
5
+ * The renderer is pure, so it emits `ref` as a placeholder and the host swaps
6
+ * in Slack's file id once the upload lands.
7
+ */
8
+ export interface SlackAssetRequest<TNode extends PrimitiveNode = PrimitiveNode> {
9
+ /** Placeholder the render emits, which the host replaces with Slack's file id. */
10
+ ref: string;
11
+ /** The node to draw as an image, to be rendered on the `snapshot` surface. */
12
+ node: TNode;
13
+ /** Accessible description, required because Slack rejects an image block without one. */
14
+ altText: string;
15
+ }
16
+ /**
17
+ * Accumulates the {@link SlackAssetRequest}s a render produced.
18
+ *
19
+ * Opt-in: without a collector, a node that cannot draw inline degrades to text
20
+ * instead, so default output stays safe for callers that cannot upload files.
21
+ */
22
+ export interface SlackAssetCollector<TNode extends PrimitiveNode = PrimitiveNode> {
23
+ /** Reserves a placeholder `ref` for `node` and records the request. */
24
+ allocate(node: TNode, altText: string): string;
25
+ /** In allocation order, so a host can upload and swap refs in one pass. */
26
+ readonly requests: readonly SlackAssetRequest<TNode>[];
27
+ }
28
+ //# sourceMappingURL=slack_assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slack_assets.d.ts","sourceRoot":"","sources":["../../src/define/slack_assets.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB,CAChC,KAAK,SAAS,aAAa,GAAG,aAAa;IAE3C,kFAAkF;IAClF,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,IAAI,EAAE,KAAK,CAAC;IACZ,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAClC,KAAK,SAAS,aAAa,GAAG,aAAa;IAE3C,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/C,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;CACxD"}