@copilotkit/shared 1.84.2-canary.1793807121 → 1.84.2-canary.openbot-intel-fixes

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/README.md +1 -1
  2. package/dist/a2ui-catalog-schema.cjs +14 -5
  3. package/dist/a2ui-catalog-schema.cjs.map +1 -1
  4. package/dist/a2ui-catalog-schema.d.cts +4 -2
  5. package/dist/a2ui-catalog-schema.d.cts.map +1 -1
  6. package/dist/a2ui-catalog-schema.d.mts +4 -2
  7. package/dist/a2ui-catalog-schema.d.mts.map +1 -1
  8. package/dist/a2ui-catalog-schema.mjs +14 -5
  9. package/dist/a2ui-catalog-schema.mjs.map +1 -1
  10. package/dist/event-transforms/open-generative-ui-middleware.cjs +7 -6
  11. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +1 -1
  12. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +1 -1
  13. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +1 -1
  14. package/dist/event-transforms/open-generative-ui-middleware.mjs +7 -6
  15. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +1 -1
  16. package/dist/generative-ui/catalog/catalog-export.cjs +329 -0
  17. package/dist/generative-ui/catalog/catalog-export.cjs.map +1 -0
  18. package/dist/generative-ui/catalog/catalog-export.d.cts +92 -0
  19. package/dist/generative-ui/catalog/catalog-export.d.cts.map +1 -0
  20. package/dist/generative-ui/catalog/catalog-export.d.mts +92 -0
  21. package/dist/generative-ui/catalog/catalog-export.d.mts.map +1 -0
  22. package/dist/generative-ui/catalog/catalog-export.mjs +328 -0
  23. package/dist/generative-ui/catalog/catalog-export.mjs.map +1 -0
  24. package/dist/generative-ui/catalog/catalog.cjs +314 -0
  25. package/dist/generative-ui/catalog/catalog.cjs.map +1 -0
  26. package/dist/generative-ui/catalog/catalog.d.cts +407 -0
  27. package/dist/generative-ui/catalog/catalog.d.cts.map +1 -0
  28. package/dist/generative-ui/catalog/catalog.d.mts +407 -0
  29. package/dist/generative-ui/catalog/catalog.d.mts.map +1 -0
  30. package/dist/generative-ui/catalog/catalog.mjs +311 -0
  31. package/dist/generative-ui/catalog/catalog.mjs.map +1 -0
  32. package/dist/generative-ui/catalog/errors.cjs +13 -0
  33. package/dist/generative-ui/catalog/errors.cjs.map +1 -0
  34. package/dist/generative-ui/catalog/errors.d.cts +46 -0
  35. package/dist/generative-ui/catalog/errors.d.cts.map +1 -0
  36. package/dist/generative-ui/catalog/errors.d.mts +46 -0
  37. package/dist/generative-ui/catalog/errors.d.mts.map +1 -0
  38. package/dist/generative-ui/catalog/errors.mjs +12 -0
  39. package/dist/generative-ui/catalog/errors.mjs.map +1 -0
  40. package/dist/generative-ui/catalog/index.d.mts +6 -0
  41. package/dist/generative-ui/catalog/json-schema.cjs +19 -0
  42. package/dist/generative-ui/catalog/json-schema.cjs.map +1 -0
  43. package/dist/generative-ui/catalog/json-schema.d.cts +13 -0
  44. package/dist/generative-ui/catalog/json-schema.d.cts.map +1 -0
  45. package/dist/generative-ui/catalog/json-schema.d.mts +13 -0
  46. package/dist/generative-ui/catalog/json-schema.d.mts.map +1 -0
  47. package/dist/generative-ui/catalog/json-schema.mjs +18 -0
  48. package/dist/generative-ui/catalog/json-schema.mjs.map +1 -0
  49. package/dist/generative-ui/catalog/refs.cjs +20 -0
  50. package/dist/generative-ui/catalog/refs.cjs.map +1 -0
  51. package/dist/generative-ui/catalog/refs.d.cts +54 -0
  52. package/dist/generative-ui/catalog/refs.d.cts.map +1 -0
  53. package/dist/generative-ui/catalog/refs.d.mts +54 -0
  54. package/dist/generative-ui/catalog/refs.d.mts.map +1 -0
  55. package/dist/generative-ui/catalog/refs.mjs +18 -0
  56. package/dist/generative-ui/catalog/refs.mjs.map +1 -0
  57. package/dist/generative-ui/catalog/schema.cjs +74 -0
  58. package/dist/generative-ui/catalog/schema.cjs.map +1 -0
  59. package/dist/generative-ui/catalog/schema.d.cts +43 -0
  60. package/dist/generative-ui/catalog/schema.d.cts.map +1 -0
  61. package/dist/generative-ui/catalog/schema.d.mts +43 -0
  62. package/dist/generative-ui/catalog/schema.d.mts.map +1 -0
  63. package/dist/generative-ui/catalog/schema.mjs +68 -0
  64. package/dist/generative-ui/catalog/schema.mjs.map +1 -0
  65. package/dist/generative-ui/index.cjs +247 -0
  66. package/dist/generative-ui/index.d.cts +33 -0
  67. package/dist/generative-ui/index.d.mts +35 -0
  68. package/dist/generative-ui/index.mjs +34 -0
  69. package/dist/generative-ui/is-record.cjs +6 -1
  70. package/dist/generative-ui/is-record.cjs.map +1 -1
  71. package/dist/generative-ui/is-record.d.cts +6 -0
  72. package/dist/generative-ui/is-record.d.cts.map +1 -0
  73. package/dist/generative-ui/is-record.d.mts +6 -0
  74. package/dist/generative-ui/is-record.d.mts.map +1 -0
  75. package/dist/generative-ui/is-record.mjs +6 -2
  76. package/dist/generative-ui/is-record.mjs.map +1 -1
  77. package/dist/generative-ui/standard/chart.cjs +56 -0
  78. package/dist/generative-ui/standard/chart.cjs.map +1 -0
  79. package/dist/generative-ui/standard/chart.d.cts +142 -0
  80. package/dist/generative-ui/standard/chart.d.cts.map +1 -0
  81. package/dist/generative-ui/standard/chart.d.mts +142 -0
  82. package/dist/generative-ui/standard/chart.d.mts.map +1 -0
  83. package/dist/generative-ui/standard/chart.mjs +54 -0
  84. package/dist/generative-ui/standard/chart.mjs.map +1 -0
  85. package/dist/generative-ui/standard/checks.cjs +74 -0
  86. package/dist/generative-ui/standard/checks.cjs.map +1 -0
  87. package/dist/generative-ui/standard/checks.d.cts +74 -0
  88. package/dist/generative-ui/standard/checks.d.cts.map +1 -0
  89. package/dist/generative-ui/standard/checks.d.mts +74 -0
  90. package/dist/generative-ui/standard/checks.d.mts.map +1 -0
  91. package/dist/generative-ui/standard/checks.mjs +71 -0
  92. package/dist/generative-ui/standard/checks.mjs.map +1 -0
  93. package/dist/generative-ui/standard/components.cjs +23 -0
  94. package/dist/generative-ui/standard/components.cjs.map +1 -0
  95. package/dist/generative-ui/standard/components.d.cts +24 -0
  96. package/dist/generative-ui/standard/components.d.cts.map +1 -0
  97. package/dist/generative-ui/standard/components.d.mts +24 -0
  98. package/dist/generative-ui/standard/components.d.mts.map +1 -0
  99. package/dist/generative-ui/standard/components.mjs +22 -0
  100. package/dist/generative-ui/standard/components.mjs.map +1 -0
  101. package/dist/generative-ui/standard/composites.cjs +143 -0
  102. package/dist/generative-ui/standard/composites.cjs.map +1 -0
  103. package/dist/generative-ui/standard/composites.d.cts +500 -0
  104. package/dist/generative-ui/standard/composites.d.cts.map +1 -0
  105. package/dist/generative-ui/standard/composites.d.mts +500 -0
  106. package/dist/generative-ui/standard/composites.d.mts.map +1 -0
  107. package/dist/generative-ui/standard/composites.mjs +132 -0
  108. package/dist/generative-ui/standard/composites.mjs.map +1 -0
  109. package/dist/generative-ui/standard/data.cjs +176 -0
  110. package/dist/generative-ui/standard/data.cjs.map +1 -0
  111. package/dist/generative-ui/standard/data.d.cts +745 -0
  112. package/dist/generative-ui/standard/data.d.cts.map +1 -0
  113. package/dist/generative-ui/standard/data.d.mts +745 -0
  114. package/dist/generative-ui/standard/data.d.mts.map +1 -0
  115. package/dist/generative-ui/standard/data.mjs +167 -0
  116. package/dist/generative-ui/standard/data.mjs.map +1 -0
  117. package/dist/generative-ui/standard/declarations.cjs +40 -0
  118. package/dist/generative-ui/standard/declarations.cjs.map +1 -0
  119. package/dist/generative-ui/standard/declarations.d.cts +4604 -0
  120. package/dist/generative-ui/standard/declarations.d.cts.map +1 -0
  121. package/dist/generative-ui/standard/declarations.d.mts +4605 -0
  122. package/dist/generative-ui/standard/declarations.d.mts.map +1 -0
  123. package/dist/generative-ui/standard/declarations.mjs +39 -0
  124. package/dist/generative-ui/standard/declarations.mjs.map +1 -0
  125. package/dist/generative-ui/standard/feedback.cjs +97 -0
  126. package/dist/generative-ui/standard/feedback.cjs.map +1 -0
  127. package/dist/generative-ui/standard/feedback.d.cts +227 -0
  128. package/dist/generative-ui/standard/feedback.d.cts.map +1 -0
  129. package/dist/generative-ui/standard/feedback.d.mts +227 -0
  130. package/dist/generative-ui/standard/feedback.d.mts.map +1 -0
  131. package/dist/generative-ui/standard/feedback.mjs +90 -0
  132. package/dist/generative-ui/standard/feedback.mjs.map +1 -0
  133. package/dist/generative-ui/standard/index.d.mts +16 -0
  134. package/dist/generative-ui/standard/inputs.cjs +333 -0
  135. package/dist/generative-ui/standard/inputs.cjs.map +1 -0
  136. package/dist/generative-ui/standard/inputs.d.cts +2658 -0
  137. package/dist/generative-ui/standard/inputs.d.cts.map +1 -0
  138. package/dist/generative-ui/standard/inputs.d.mts +2658 -0
  139. package/dist/generative-ui/standard/inputs.d.mts.map +1 -0
  140. package/dist/generative-ui/standard/inputs.mjs +318 -0
  141. package/dist/generative-ui/standard/inputs.mjs.map +1 -0
  142. package/dist/generative-ui/standard/layout.cjs +289 -0
  143. package/dist/generative-ui/standard/layout.cjs.map +1 -0
  144. package/dist/generative-ui/standard/layout.d.cts +2854 -0
  145. package/dist/generative-ui/standard/layout.d.cts.map +1 -0
  146. package/dist/generative-ui/standard/layout.d.mts +2854 -0
  147. package/dist/generative-ui/standard/layout.d.mts.map +1 -0
  148. package/dist/generative-ui/standard/layout.mjs +269 -0
  149. package/dist/generative-ui/standard/layout.mjs.map +1 -0
  150. package/dist/generative-ui/standard/map.cjs +27 -0
  151. package/dist/generative-ui/standard/map.cjs.map +1 -0
  152. package/dist/generative-ui/standard/map.d.cts +93 -0
  153. package/dist/generative-ui/standard/map.d.cts.map +1 -0
  154. package/dist/generative-ui/standard/map.d.mts +93 -0
  155. package/dist/generative-ui/standard/map.d.mts.map +1 -0
  156. package/dist/generative-ui/standard/map.mjs +25 -0
  157. package/dist/generative-ui/standard/map.mjs.map +1 -0
  158. package/dist/generative-ui/standard/media.cjs +215 -0
  159. package/dist/generative-ui/standard/media.cjs.map +1 -0
  160. package/dist/generative-ui/standard/media.d.cts +968 -0
  161. package/dist/generative-ui/standard/media.d.cts.map +1 -0
  162. package/dist/generative-ui/standard/media.d.mts +968 -0
  163. package/dist/generative-ui/standard/media.d.mts.map +1 -0
  164. package/dist/generative-ui/standard/media.mjs +205 -0
  165. package/dist/generative-ui/standard/media.mjs.map +1 -0
  166. package/dist/generative-ui/standard/parameter-order.cjs +231 -0
  167. package/dist/generative-ui/standard/parameter-order.cjs.map +1 -0
  168. package/dist/generative-ui/standard/parameter-order.d.cts +84 -0
  169. package/dist/generative-ui/standard/parameter-order.d.cts.map +1 -0
  170. package/dist/generative-ui/standard/parameter-order.d.mts +84 -0
  171. package/dist/generative-ui/standard/parameter-order.d.mts.map +1 -0
  172. package/dist/generative-ui/standard/parameter-order.mjs +230 -0
  173. package/dist/generative-ui/standard/parameter-order.mjs.map +1 -0
  174. package/dist/generative-ui/standard/styles.cjs +62 -0
  175. package/dist/generative-ui/standard/styles.cjs.map +1 -0
  176. package/dist/generative-ui/standard/styles.d.cts +17 -0
  177. package/dist/generative-ui/standard/styles.d.cts.map +1 -0
  178. package/dist/generative-ui/standard/styles.d.mts +17 -0
  179. package/dist/generative-ui/standard/styles.d.mts.map +1 -0
  180. package/dist/generative-ui/standard/styles.mjs +60 -0
  181. package/dist/generative-ui/standard/styles.mjs.map +1 -0
  182. package/dist/generative-ui/standard/text.cjs +226 -0
  183. package/dist/generative-ui/standard/text.cjs.map +1 -0
  184. package/dist/generative-ui/standard/text.d.cts +687 -0
  185. package/dist/generative-ui/standard/text.d.cts.map +1 -0
  186. package/dist/generative-ui/standard/text.d.mts +687 -0
  187. package/dist/generative-ui/standard/text.d.mts.map +1 -0
  188. package/dist/generative-ui/standard/text.mjs +209 -0
  189. package/dist/generative-ui/standard/text.mjs.map +1 -0
  190. package/dist/generative-ui/standard/theme.cjs +115 -0
  191. package/dist/generative-ui/standard/theme.cjs.map +1 -0
  192. package/dist/generative-ui/standard/theme.d.cts +60 -0
  193. package/dist/generative-ui/standard/theme.d.cts.map +1 -0
  194. package/dist/generative-ui/standard/theme.d.mts +60 -0
  195. package/dist/generative-ui/standard/theme.d.mts.map +1 -0
  196. package/dist/generative-ui/standard/theme.mjs +112 -0
  197. package/dist/generative-ui/standard/theme.mjs.map +1 -0
  198. package/dist/generative-ui/standard/tokens.cjs +336 -0
  199. package/dist/generative-ui/standard/tokens.cjs.map +1 -0
  200. package/dist/generative-ui/standard/tokens.d.cts +76 -0
  201. package/dist/generative-ui/standard/tokens.d.cts.map +1 -0
  202. package/dist/generative-ui/standard/tokens.d.mts +76 -0
  203. package/dist/generative-ui/standard/tokens.d.mts.map +1 -0
  204. package/dist/generative-ui/standard/tokens.mjs +305 -0
  205. package/dist/generative-ui/standard/tokens.mjs.map +1 -0
  206. package/dist/index.cjs.map +1 -1
  207. package/dist/index.d.cts +10 -10
  208. package/dist/index.d.mts +10 -10
  209. package/dist/index.mjs.map +1 -1
  210. package/dist/index.umd.js +16 -7
  211. package/dist/index.umd.js.map +1 -1
  212. package/dist/package.cjs +1 -1
  213. package/dist/package.mjs +1 -1
  214. package/package.json +7 -3
  215. package/src/__tests__/a2ui-catalog-schema.test.ts +26 -0
  216. package/src/a2ui-catalog-schema.ts +14 -5
  217. package/src/event-transforms/open-generative-ui-middleware.ts +19 -10
  218. package/src/generative-ui/base.ts +9 -0
  219. package/src/generative-ui/catalog/catalog-export.ts +478 -0
  220. package/src/generative-ui/catalog/catalog.ts +1166 -0
  221. package/src/generative-ui/catalog/errors.ts +102 -0
  222. package/src/generative-ui/catalog/index.ts +6 -0
  223. package/src/generative-ui/catalog/json-schema.ts +23 -0
  224. package/src/generative-ui/catalog/refs.ts +86 -0
  225. package/src/generative-ui/catalog/schema.ts +107 -0
  226. package/src/generative-ui/index.ts +7 -0
  227. package/src/generative-ui/is-record.ts +6 -1
  228. package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
  229. package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
  230. package/src/generative-ui/standard/chart.ts +79 -0
  231. package/src/generative-ui/standard/checks.ts +98 -0
  232. package/src/generative-ui/standard/components.ts +35 -0
  233. package/src/generative-ui/standard/composites.ts +158 -0
  234. package/src/generative-ui/standard/data.ts +213 -0
  235. package/src/generative-ui/standard/declarations.ts +57 -0
  236. package/src/generative-ui/standard/feedback.ts +105 -0
  237. package/src/generative-ui/standard/index.ts +19 -0
  238. package/src/generative-ui/standard/inputs.ts +423 -0
  239. package/src/generative-ui/standard/layout.ts +312 -0
  240. package/src/generative-ui/standard/map.ts +32 -0
  241. package/src/generative-ui/standard/media.ts +265 -0
  242. package/src/generative-ui/standard/parameter-order.ts +155 -0
  243. package/src/generative-ui/standard/styles.ts +79 -0
  244. package/src/generative-ui/standard/text.ts +210 -0
  245. package/src/generative-ui/standard/theme.ts +198 -0
  246. package/src/generative-ui/standard/tokens.ts +317 -0
  247. package/src/index.ts +1 -1
  248. package/tsdown.config.ts +1 -0
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "1.84.2-canary.1793807121";
3
+ var version = "1.84.2-canary.openbot-intel-fixes";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.84.2-canary.1793807121";
2
+ var version = "1.84.2-canary.openbot-intel-fixes";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/shared",
3
- "version": "1.84.2-canary.1793807121",
3
+ "version": "1.84.2-canary.openbot-intel-fixes",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -36,6 +36,10 @@
36
36
  "import": "./dist/event-transforms/index.mjs",
37
37
  "require": "./dist/event-transforms/index.cjs"
38
38
  },
39
+ "./generative-ui": {
40
+ "import": "./dist/generative-ui/index.mjs",
41
+ "require": "./dist/generative-ui/index.cjs"
42
+ },
39
43
  "./telemetry": {
40
44
  "import": "./dist/telemetry/index.mjs",
41
45
  "require": "./dist/telemetry/index.cjs"
@@ -57,7 +61,7 @@
57
61
  },
58
62
  "dependencies": {
59
63
  "@ag-ui/a2ui-middleware": "0.0.10",
60
- "@ag-ui/client": "1.0.4-canary.1793805408.0",
64
+ "@ag-ui/client": "1.0.2",
61
65
  "@copilotkit/license-verifier": "~0.5.0",
62
66
  "@segment/analytics-node": "^2.1.2",
63
67
  "@standard-schema/spec": "^1.0.0",
@@ -70,7 +74,7 @@
70
74
  "zod-to-json-schema": "^3.23.5"
71
75
  },
72
76
  "devDependencies": {
73
- "@ag-ui/core": "1.0.4-canary.1793805408.0",
77
+ "@ag-ui/core": "1.0.2",
74
78
  "@types/clarinet": "^0.12.3",
75
79
  "@types/uuid": "^10.0.0",
76
80
  "@valibot/to-json-schema": "^1.5.0",
@@ -93,6 +93,32 @@ describe("extractA2UICatalogSchemas", () => {
93
93
  expect(schema).not.toHaveProperty(["common_types.json"]);
94
94
  });
95
95
 
96
+ it("writes a local #/$defs REF marker as a common_types.json ref", () => {
97
+ // web_core 0.15's v0.9 common types mark themselves REF:#/$defs/<Name>.
98
+ const id = z.string().describe("REF:#/$defs/ComponentId|Child id");
99
+ const schema = extractA2UICatalogSchemas(
100
+ catalog({
101
+ Card: z.object({
102
+ child: id,
103
+ other: z
104
+ .string()
105
+ .describe("REF:common_types.json#/$defs/ComponentId"),
106
+ }),
107
+ }),
108
+ );
109
+
110
+ expect(props(schema, "Card")).toEqual({
111
+ component: { const: "Card" },
112
+ child: {
113
+ $ref: "common_types.json#/$defs/ComponentId",
114
+ description: "Child id",
115
+ },
116
+ other: { $ref: "common_types.json#/$defs/ComponentId" },
117
+ });
118
+ expect(commonTypes(schema)).toEqual({ ComponentId: { type: "string" } });
119
+ expect(JSON.stringify(schema)).not.toContain('"$ref":"#/');
120
+ });
121
+
96
122
  it("keeps a use whose shape differs from the stored type inline", () => {
97
123
  const schema = extractA2UICatalogSchemas(
98
124
  catalog({
@@ -71,8 +71,10 @@ export type A2UICommonTypes = Record<string, JsonSchema>;
71
71
  *
72
72
  * - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which
73
73
  * would dangle once properties move under `allOf[1]`.
74
- * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but
75
- * the shape it replaced is kept once under
74
+ * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream.
75
+ * Upstream writes a common type as a local `#/$defs/<Name>` ref, which an
76
+ * inline catalog without `$defs` leaves dangling; here it is always
77
+ * `common_types.json#/$defs/<Name>`, and the shape it replaced is kept once under
76
78
  * `"common_types.json": { "$defs": { <Name>: ... } }`. Every
77
79
  * `common_types.json#/$defs/<Name>` ref therefore resolves within the
78
80
  * payload, both for agents that only see it as prompt text and for SDKs
@@ -287,7 +289,14 @@ const SUBSCHEMA_MAP_KEYWORDS = [
287
289
  "definitions",
288
290
  ];
289
291
 
290
- const COMMON_TYPE_REF = /^common_types\.json#\/\$defs\/([^/]+)$/;
292
+ /**
293
+ * A reference to a whole common type, in `common_types.json` or local. From
294
+ * `@a2ui/web_core` 0.15 the v0.9 common types mark themselves with local
295
+ * `REF:#/$defs/<Name>` refs, the layout of a bundled catalog document; both
296
+ * forms name the same type, which this payload writes as
297
+ * `common_types.json#/$defs/<Name>`.
298
+ */
299
+ const COMMON_TYPE_REF = /^(?:common_types\.json)?#\/\$defs\/([^/]+)$/;
291
300
 
292
301
  function isObject(value: unknown): value is JsonSchema {
293
302
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -358,11 +367,11 @@ function resolveRefMarker(
358
367
  if (!marker) return node;
359
368
 
360
369
  const { description: _marker, ...shape } = node;
370
+ const name = COMMON_TYPE_REF.exec(marker.ref)?.[1];
361
371
  const ref: JsonSchema = {
362
- $ref: marker.ref,
372
+ $ref: name === undefined ? marker.ref : `common_types.json#/$defs/${name}`,
363
373
  ...(marker.description ? { description: marker.description } : {}),
364
374
  };
365
- const name = COMMON_TYPE_REF.exec(marker.ref)?.[1];
366
375
  if (name !== undefined) {
367
376
  const known = commonTypes[name];
368
377
  if (known === undefined) {
@@ -251,16 +251,23 @@ export class ArgsParser {
251
251
  }
252
252
  }
253
253
 
254
+ /**
255
+ * Extract EventWithState type from Middleware.runNextWithState return type
256
+ */
257
+ type ExtractObservableType<T> = T extends Observable<infer U> ? U : never;
258
+ type RunNextWithStateReturn = ReturnType<Middleware["runNextWithState"]>;
259
+ type EventWithState = ExtractObservableType<RunNextWithStateReturn>;
260
+
254
261
  export class OpenGenerativeUIMiddleware extends Middleware {
255
262
  run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {
256
- // Only the events are read, so `runNext`: `runNextWithState` copies the
257
- // messages and state on every event for a consumer that never looks.
258
- return this.processStream(this.runNext(input, next));
263
+ return this.processStream(this.runNextWithState(input, next));
259
264
  }
260
265
 
261
- private processStream(source: Observable<BaseEvent>): Observable<BaseEvent> {
266
+ private processStream(
267
+ source: Observable<EventWithState>,
268
+ ): Observable<BaseEvent> {
262
269
  return new Observable<BaseEvent>((subscriber) => {
263
- let heldRunFinished: BaseEvent | null = null;
270
+ let heldRunFinished: EventWithState | null = null;
264
271
  // Track active generateSandboxedUi tool call IDs → their streaming parser
265
272
  const activeParsers = new Map<string, ArgsParser>();
266
273
  // Hold genui tool call events until the first activity event is emitted
@@ -280,14 +287,16 @@ export class OpenGenerativeUIMiddleware extends Middleware {
280
287
  };
281
288
 
282
289
  const subscription = source.subscribe({
283
- next: (event) => {
290
+ next: (eventWithState) => {
291
+ const event = eventWithState.event;
292
+
284
293
  if (heldRunFinished) {
285
- subscriber.next(heldRunFinished);
294
+ subscriber.next(heldRunFinished.event);
286
295
  heldRunFinished = null;
287
296
  }
288
297
 
289
298
  if (event.type === EventType.RUN_FINISHED) {
290
- heldRunFinished = event;
299
+ heldRunFinished = eventWithState;
291
300
  return;
292
301
  }
293
302
 
@@ -357,7 +366,7 @@ export class OpenGenerativeUIMiddleware extends Middleware {
357
366
  heldToolCallEvents.clear();
358
367
 
359
368
  if (heldRunFinished) {
360
- subscriber.next(heldRunFinished);
369
+ subscriber.next(heldRunFinished.event);
361
370
  heldRunFinished = null;
362
371
  }
363
372
  subscriber.error(err);
@@ -369,7 +378,7 @@ export class OpenGenerativeUIMiddleware extends Middleware {
369
378
  });
370
379
 
371
380
  if (heldRunFinished) {
372
- subscriber.next(heldRunFinished);
381
+ subscriber.next(heldRunFinished.event);
373
382
  heldRunFinished = null;
374
383
  }
375
384
  activeParsers.clear();
@@ -0,0 +1,9 @@
1
+ export * from "./types";
2
+ export * from "./validate-operation";
3
+ export * from "./render-ui-args";
4
+ export * from "./basic-functions";
5
+ export * from "./child-refs";
6
+ export * from "./prompt";
7
+ export { buildCompactGenerativeUISchema } from "./compact-schema";
8
+ export * from "./prompt-spec";
9
+ export * from "./schema-render";
@@ -0,0 +1,478 @@
1
+ import {
2
+ A2UI_CHILD_LIST_REF,
3
+ A2UI_COMPONENT_ID_REF,
4
+ GENERATIVE_UI_FUNCTIONS,
5
+ childRefKind,
6
+ functionCallers,
7
+ } from "../base";
8
+ import type {
9
+ A2UIAllowedCallers,
10
+ A2UIFunctionPermissions,
11
+ GenerativeUIComponentManifest,
12
+ GenerativeUIJSONSchema,
13
+ } from "../base";
14
+ import type { GenerativeUI } from "./catalog";
15
+ import { toJsonSchema } from "./json-schema";
16
+ import { hasOwnKey, isRecord } from "../is-record";
17
+
18
+ const COMMON = "common_types.json#/$defs/";
19
+ const DATA_BINDING_REF = `${COMMON}DataBinding`;
20
+ const FUNCTION_CALL_REF = `${COMMON}FunctionCall`;
21
+ const ACTION_REF = `${COMMON}Action`;
22
+ const DYNAMIC_REFS: Record<string, string> = {
23
+ string: `${COMMON}DynamicString`,
24
+ number: `${COMMON}DynamicNumber`,
25
+ boolean: `${COMMON}DynamicBoolean`,
26
+ "string[]": `${COMMON}DynamicStringList`,
27
+ unknown: `${COMMON}DynamicValue`,
28
+ };
29
+
30
+ /** What `exportA2UICatalog` adds at the top of the catalog. */
31
+ export interface ExportA2UICatalogOptions {
32
+ /** The title of the catalog. */
33
+ title?: string;
34
+ /** What the catalog is for. */
35
+ description?: string;
36
+ /** Markdown design guidelines for a model that writes this catalog. */
37
+ instructions?: string;
38
+ }
39
+
40
+ /**
41
+ * The A2UI 1.0 catalog definition of a generative UI, as a JSON value that
42
+ * follows `catalog_definition.json`: one `components` entry per component,
43
+ * with `component` as a `const`, `functions` for the built-ins and the
44
+ * declared functions, and `$defs.anyComponent` / `$defs.anyFunction`. Other
45
+ * A2UI tools (a validator, another renderer, a prompt builder) read it.
46
+ *
47
+ * - A prop that `child()` or `childList()` marks is a `ComponentId` or a
48
+ * `ChildList` reference; so is a slot. An event prop is an `Action`.
49
+ * - Every other value, at any depth of a prop or of the args of a declared
50
+ * function, takes its literal schema, a `DataBinding` or a `FunctionCall`,
51
+ * because the renderer resolves dynamic values at any depth.
52
+ * - Every function states `returnType` and `allowedCallers`: the built-ins
53
+ * are `rendererOnly`, and so is a declared function without
54
+ * `allowedCallers`, as in A2UI 1.0.
55
+ *
56
+ * @param ui - The generative UI to describe.
57
+ * @param options - The title, description and instructions of the catalog.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const catalog = exportA2UICatalog(shopUI, { title: "Acme shop" });
62
+ * fs.writeFileSync("shop-catalog.json", JSON.stringify(catalog, null, 2));
63
+ * ```
64
+ */
65
+ export function exportA2UICatalog(
66
+ ui: GenerativeUI,
67
+ options: ExportA2UICatalogOptions = {},
68
+ ) {
69
+ const components = Object.fromEntries(
70
+ Object.entries(ui.manifestComponents).map(([name, manifest]) => [
71
+ name,
72
+ toDraft2020(
73
+ rebaseRefs(
74
+ componentDefinition(name, manifest),
75
+ `#/components/${pointerSegment(name)}`,
76
+ ),
77
+ ),
78
+ ]),
79
+ );
80
+ const functions: Record<string, GenerativeUIJSONSchema> = {};
81
+ for (const [name, info] of Object.entries(GENERATIVE_UI_FUNCTIONS)) {
82
+ // A declared function of the same name is the app's.
83
+ if (ui.functions.has(name)) continue;
84
+ functions[name] = functionEntry(name, info, {
85
+ description: info.description,
86
+ returnType: info.returnType,
87
+ args: argsSchemaFromSignature(info.parameters),
88
+ });
89
+ }
90
+ for (const [name, fn] of ui.functions) {
91
+ functions[name] = functionEntry(name, fn, {
92
+ description: fn.description,
93
+ returnType: fn.returnType ?? "any",
94
+ args: toDraft2020(
95
+ rebaseRefs(
96
+ dynamicArgs(toJsonSchema(fn.parameters)),
97
+ `#/functions/${pointerSegment(name)}/properties/args`,
98
+ ),
99
+ ),
100
+ });
101
+ }
102
+ const { title, description, instructions } = options;
103
+ return {
104
+ $schema: "https://json-schema.org/draft/2020-12/schema",
105
+ protocolVersion: "1.0",
106
+ catalogId: ui.id,
107
+ ...(title === undefined ? {} : { title }),
108
+ ...(description === undefined ? {} : { description }),
109
+ ...(instructions === undefined ? {} : { instructions }),
110
+ components,
111
+ functions,
112
+ $defs: {
113
+ anyComponent: {
114
+ ...oneOfRefs("components", Object.keys(components)),
115
+ discriminator: { propertyName: "component" },
116
+ },
117
+ anyFunction: oneOfRefs("functions", Object.keys(functions)),
118
+ },
119
+ };
120
+ }
121
+
122
+ /**
123
+ * `oneOf` over the entries of a section. JSON Schema wants at least one
124
+ * variant, so an empty section (a UI with no components) matches nothing.
125
+ */
126
+ function oneOfRefs(section: string, names: string[]) {
127
+ if (names.length === 0) return { not: {} };
128
+ return {
129
+ oneOf: names.map((name) => ({
130
+ $ref: `#/${section}/${pointerSegment(name)}`,
131
+ })),
132
+ };
133
+ }
134
+
135
+ /** A name as a JSON Pointer segment in a URI fragment: `acme/Card` is `acme~1Card`. */
136
+ function pointerSegment(name: string) {
137
+ return encodeURIComponent(name.replace(/~/g, "~0").replace(/\//g, "~1"));
138
+ }
139
+
140
+ /** Keywords whose value is data, not a schema. */
141
+ const LITERAL_KEYWORDS = new Set(["default", "const", "enum", "examples"]);
142
+
143
+ /**
144
+ * A schema in the draft 2020-12 dialect that the catalog declares. The
145
+ * converter writes draft-07, where a tuple is `items: [...]` with
146
+ * `additionalItems`; 2020-12 spells that `prefixItems` and `items`.
147
+ */
148
+ function toDraft2020(schema: GenerativeUIJSONSchema): GenerativeUIJSONSchema {
149
+ return mapSchema(schema, (node) => {
150
+ const { items, additionalItems, ...rest } = node;
151
+ if (!Array.isArray(items)) return node;
152
+ return {
153
+ ...rest,
154
+ prefixItems: items,
155
+ ...(additionalItems === undefined ? {} : { items: additionalItems }),
156
+ };
157
+ });
158
+ }
159
+
160
+ /** One `components` entry: the props as the model sets them, with the A2UI common types. */
161
+ function componentDefinition(
162
+ name: string,
163
+ manifest: GenerativeUIComponentManifest,
164
+ ): GenerativeUIJSONSchema {
165
+ const { properties, required, description, $defs, definitions } =
166
+ manifest.props;
167
+ const props = Object.fromEntries(
168
+ Object.entries(isRecord(properties) ? properties : {}).map(
169
+ ([key, schema]) => [key, dynamicProp(schema)],
170
+ ),
171
+ );
172
+ const events = Object.fromEntries(
173
+ Object.entries(manifest.events ?? {}).map(([key, event]) => [
174
+ key,
175
+ {
176
+ $ref: ACTION_REF,
177
+ ...(event.description ? { description: event.description } : {}),
178
+ },
179
+ ]),
180
+ );
181
+ const slots = Object.fromEntries(
182
+ Object.entries(manifest.slots ?? {}).map(([key, kind]) => [
183
+ key,
184
+ { $ref: kind === "single" ? A2UI_COMPONENT_ID_REF : A2UI_CHILD_LIST_REF },
185
+ ]),
186
+ );
187
+ const fields = { ...props, ...events, ...slots };
188
+ const orderedFields =
189
+ manifest.parameterOrder === undefined
190
+ ? fields
191
+ : Object.fromEntries(
192
+ [...new Set([...manifest.parameterOrder, ...Object.keys(fields)])]
193
+ .filter((key) => hasOwnKey(fields, key))
194
+ .map((key) => [key, fields[key]]),
195
+ );
196
+ const text = manifest.description ?? description;
197
+ return {
198
+ type: "object",
199
+ ...(typeof text === "string" ? { description: text } : {}),
200
+ properties: { component: { const: name }, ...orderedFields },
201
+ required: [
202
+ "component",
203
+ ...(Array.isArray(required) ? required.filter(isString) : []),
204
+ ],
205
+ // The definitions of the props schema, when its converter made some:
206
+ // their values are dynamic like the props, and the references to them
207
+ // are rebased onto this entry.
208
+ ...withDynamicChildren({
209
+ ...(isRecord($defs) ? { $defs } : {}),
210
+ ...(isRecord(definitions) ? { definitions } : {}),
211
+ }),
212
+ };
213
+ }
214
+
215
+ /**
216
+ * The schema with its local references (`#/...`) pointing into the place
217
+ * it is embedded at. A converter that writes `$defs` refers to them from
218
+ * the root of its own document; inside the catalog, that root is `base`.
219
+ */
220
+ function rebaseRefs(
221
+ schema: GenerativeUIJSONSchema,
222
+ base: string,
223
+ ): GenerativeUIJSONSchema {
224
+ return mapSchema(schema, (node) => {
225
+ const ref = node.$ref;
226
+ // "#" is the root of the embedded schema (a recursive one refers to it).
227
+ if (ref === "#") return { ...node, $ref: base };
228
+ if (typeof ref === "string" && ref.startsWith("#/")) {
229
+ return { ...node, $ref: `${base}${ref.slice(1)}` };
230
+ }
231
+ return node;
232
+ });
233
+ }
234
+
235
+ /** Keywords whose value is a map from a name to a schema. */
236
+ const SCHEMA_MAP_KEYWORDS = new Set([
237
+ "properties",
238
+ "patternProperties",
239
+ "$defs",
240
+ "definitions",
241
+ "dependentSchemas",
242
+ ]);
243
+
244
+ /**
245
+ * Walks a JSON Schema and rebuilds each schema node with `transform`, the
246
+ * children first. The names in `properties` and the definition maps are
247
+ * names, not keywords: a prop called `default` is a schema, while the
248
+ * `default` of a schema is data and stays as it is.
249
+ */
250
+ function mapSchema(
251
+ schema: GenerativeUIJSONSchema,
252
+ transform: (node: Record<string, unknown>) => Record<string, unknown>,
253
+ ): GenerativeUIJSONSchema {
254
+ const visitValue = (value: unknown): unknown => {
255
+ if (Array.isArray(value)) return value.map(visitValue);
256
+ return isRecord(value) ? visitNode(value) : value;
257
+ };
258
+ const visitNode = (
259
+ node: Record<string, unknown>,
260
+ ): Record<string, unknown> => {
261
+ const result: Record<string, unknown> = {};
262
+ for (const [key, value] of Object.entries(node)) {
263
+ if (LITERAL_KEYWORDS.has(key)) result[key] = value;
264
+ else if (SCHEMA_MAP_KEYWORDS.has(key) && isRecord(value)) {
265
+ result[key] = Object.fromEntries(
266
+ Object.entries(value).map(([name, entry]) => [
267
+ name,
268
+ isRecord(entry) ? visitNode(entry) : entry,
269
+ ]),
270
+ );
271
+ } else result[key] = visitValue(value);
272
+ }
273
+ return transform(result);
274
+ };
275
+ return visitNode(schema) as GenerativeUIJSONSchema;
276
+ }
277
+
278
+ const isString = (value: unknown): value is string => typeof value === "string";
279
+
280
+ /**
281
+ * A prop as the catalog states it. A component reference stays one. Any
282
+ * other value takes its literal schema, a data binding or a function call,
283
+ * and so does every value inside it: the properties of an object, the
284
+ * values of a record and the items of a list, because the renderer
285
+ * resolves dynamic values at any depth. The variants of a union are
286
+ * transformed in place.
287
+ */
288
+ function dynamicProp(schema: unknown): GenerativeUIJSONSchema {
289
+ if (!isRecord(schema)) return { $ref: DYNAMIC_REFS.unknown };
290
+ if (childRefKind(schema)) return schema;
291
+ const { description, ...literal } = withDynamicChildren(schema);
292
+ return {
293
+ ...(typeof description === "string" ? { description } : {}),
294
+ anyOf: [literal, { $ref: DATA_BINDING_REF }, { $ref: FUNCTION_CALL_REF }],
295
+ };
296
+ }
297
+
298
+ /** The schema with its nested values made dynamic, itself unchanged. */
299
+ function withDynamicChildren(
300
+ schema: Record<string, unknown>,
301
+ ): Record<string, unknown> {
302
+ const result = { ...schema };
303
+ if (isRecord(schema.properties)) {
304
+ result.properties = Object.fromEntries(
305
+ Object.entries(schema.properties).map(([key, value]) => [
306
+ key,
307
+ dynamicProp(value),
308
+ ]),
309
+ );
310
+ }
311
+ if (isRecord(schema.items)) result.items = dynamicProp(schema.items);
312
+ // A tuple, as the converter writes it; the catalog spells it prefixItems.
313
+ if (Array.isArray(schema.items)) {
314
+ result.items = schema.items.map((item) =>
315
+ isRecord(item) ? dynamicProp(item) : item,
316
+ );
317
+ }
318
+ if (isRecord(schema.additionalItems)) {
319
+ result.additionalItems = dynamicProp(schema.additionalItems);
320
+ }
321
+ // The definitions a converter wrote: referenced from value positions.
322
+ for (const key of ["$defs", "definitions"] as const) {
323
+ const defs = schema[key];
324
+ if (isRecord(defs)) {
325
+ result[key] = Object.fromEntries(
326
+ Object.entries(defs).map(([name, def]) => [
327
+ name,
328
+ isRecord(def) ? withDynamicChildren(def) : def,
329
+ ]),
330
+ );
331
+ }
332
+ }
333
+ if (Array.isArray(schema.allOf)) {
334
+ result.allOf = schema.allOf.map((part) =>
335
+ isRecord(part) ? withDynamicChildren(part) : part,
336
+ );
337
+ }
338
+ // The values of a record, by any key or by key pattern.
339
+ if (isRecord(schema.additionalProperties)) {
340
+ result.additionalProperties = dynamicProp(schema.additionalProperties);
341
+ }
342
+ if (isRecord(schema.patternProperties)) {
343
+ result.patternProperties = Object.fromEntries(
344
+ Object.entries(schema.patternProperties).map(([pattern, value]) => [
345
+ pattern,
346
+ dynamicProp(value),
347
+ ]),
348
+ );
349
+ }
350
+ for (const key of ["anyOf", "oneOf"] as const) {
351
+ const variants = schema[key];
352
+ if (Array.isArray(variants)) {
353
+ result[key] = variants.map((variant) =>
354
+ isRecord(variant) && !childRefKind(variant)
355
+ ? withDynamicChildren(variant)
356
+ : variant,
357
+ );
358
+ }
359
+ }
360
+ return result;
361
+ }
362
+
363
+ /**
364
+ * The args of a declared function as the catalog states them: the object
365
+ * stays an object, each arg takes a value, a binding or a function call.
366
+ */
367
+ function dynamicArgs(schema: GenerativeUIJSONSchema): GenerativeUIJSONSchema {
368
+ return withDynamicChildren(schema);
369
+ }
370
+
371
+ /** One `functions` entry, in the A2UI `FunctionDefinition` shape. */
372
+ function functionEntry(
373
+ name: string,
374
+ permissions: A2UIFunctionPermissions,
375
+ parts: {
376
+ description: string | undefined;
377
+ returnType: string;
378
+ args: GenerativeUIJSONSchema;
379
+ },
380
+ ): GenerativeUIJSONSchema {
381
+ const callers = functionCallers(permissions);
382
+ const allowedCallers: A2UIAllowedCallers =
383
+ callers.renderer && callers.agent
384
+ ? "rendererOrAgent"
385
+ : callers.agent
386
+ ? "agentOnly"
387
+ : "rendererOnly";
388
+ // The metaschema's activation rule has no `required`, so it also matches
389
+ // an entry without the key: the value is always written out.
390
+ // `args` is required only when an arg is.
391
+ const argsRequired = hasRequiredArgs(parts.args);
392
+ return {
393
+ type: "object",
394
+ ...(parts.description ? { description: parts.description } : {}),
395
+ returnType: parts.returnType,
396
+ allowedCallers,
397
+ requiresUserActivation: permissions.requiresUserActivation === true,
398
+ properties: { "@call": { const: name }, args: parts.args },
399
+ required: argsRequired ? ["@call", "args"] : ["@call"],
400
+ };
401
+ }
402
+
403
+ /**
404
+ * True when an empty args object fails the schema: a key is required at
405
+ * its top, in an `allOf` part, or in every variant of an `anyOf` / `oneOf`.
406
+ */
407
+ function hasRequiredArgs(schema: unknown): boolean {
408
+ if (!isRecord(schema)) return false;
409
+ if (Array.isArray(schema.required) && schema.required.length > 0) return true;
410
+ if (Array.isArray(schema.allOf) && schema.allOf.some(hasRequiredArgs)) {
411
+ return true;
412
+ }
413
+ for (const key of ["anyOf", "oneOf"] as const) {
414
+ const variants = schema[key];
415
+ if (Array.isArray(variants) && variants.length > 0) {
416
+ if (variants.every(hasRequiredArgs)) return true;
417
+ }
418
+ }
419
+ return false;
420
+ }
421
+
422
+ /**
423
+ * The JSON Schema of the args of a built-in function, from its short
424
+ * TypeScript-like signature (`{ value: number; decimals?: number }`). Each
425
+ * arg takes a literal, a binding or a function call, so a type maps to the
426
+ * A2UI dynamic type; `[name: string]: T` becomes `additionalProperties`.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * argsSchemaFromSignature("{ value: string; min?: number }");
431
+ * // { type: "object", properties: { value: { $ref: ".../DynamicString" }, min: { $ref: ".../DynamicNumber" } }, required: ["value"], additionalProperties: false }
432
+ * ```
433
+ */
434
+ export function argsSchemaFromSignature(
435
+ signature: string,
436
+ ): GenerativeUIJSONSchema {
437
+ const body = signature.trim().replace(/^\{/, "").replace(/\}$/, "");
438
+ const properties: Record<string, GenerativeUIJSONSchema> = {};
439
+ const required: string[] = [];
440
+ let additionalProperties: GenerativeUIJSONSchema | false = false;
441
+ for (const part of body.split(";")) {
442
+ const field = part.trim();
443
+ if (field === "") continue;
444
+ const index = field.match(/^\[\w+: string\]:\s*(.+)$/);
445
+ if (index) {
446
+ additionalProperties = typeSchema(index[1]);
447
+ continue;
448
+ }
449
+ const named = field.match(/^(\w+)(\?)?:\s*(.+)$/);
450
+ if (!named) continue;
451
+ properties[named[1]] = typeSchema(named[3]);
452
+ if (!named[2]) required.push(named[1]);
453
+ }
454
+ return {
455
+ type: "object",
456
+ properties,
457
+ ...(required.length > 0 ? { required } : {}),
458
+ additionalProperties,
459
+ };
460
+ }
461
+
462
+ function typeSchema(type: string): GenerativeUIJSONSchema {
463
+ const trimmed = type.trim();
464
+ const alternatives = trimmed.split("|").map((part) => part.trim());
465
+ if (alternatives.length > 1) return { anyOf: alternatives.map(typeSchema) };
466
+ if (trimmed in DYNAMIC_REFS) return { $ref: DYNAMIC_REFS[trimmed] };
467
+ if (trimmed.endsWith("[]")) {
468
+ // The whole list can be bound or computed, like any other arg.
469
+ return {
470
+ anyOf: [
471
+ { type: "array", items: typeSchema(trimmed.slice(0, -2)) },
472
+ { $ref: DATA_BINDING_REF },
473
+ { $ref: FUNCTION_CALL_REF },
474
+ ],
475
+ };
476
+ }
477
+ return { $ref: DYNAMIC_REFS.unknown };
478
+ }