@copilotkit/shared 2.0.0-rc.3 → 2.0.0-rc.31

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 (287) hide show
  1. package/README.md +3 -14
  2. package/dist/a2ui-envelope.cjs +2 -2
  3. package/dist/a2ui-envelope.cjs.map +1 -1
  4. package/dist/a2ui-envelope.d.cts +1 -1
  5. package/dist/a2ui-envelope.d.cts.map +1 -1
  6. package/dist/a2ui-envelope.d.mts +1 -1
  7. package/dist/a2ui-envelope.d.mts.map +1 -1
  8. package/dist/a2ui-envelope.mjs +2 -2
  9. package/dist/a2ui-envelope.mjs.map +1 -1
  10. package/dist/a2ui-prompts.cjs +21 -62
  11. package/dist/a2ui-prompts.cjs.map +1 -1
  12. package/dist/a2ui-prompts.d.cts +8 -1
  13. package/dist/a2ui-prompts.d.cts.map +1 -1
  14. package/dist/a2ui-prompts.d.mts +8 -1
  15. package/dist/a2ui-prompts.d.mts.map +1 -1
  16. package/dist/a2ui-prompts.mjs +22 -62
  17. package/dist/a2ui-prompts.mjs.map +1 -1
  18. package/dist/attachments/types.d.cts +1 -3
  19. package/dist/attachments/types.d.cts.map +1 -1
  20. package/dist/attachments/types.d.mts +1 -3
  21. package/dist/attachments/types.d.mts.map +1 -1
  22. package/dist/attachments/utils.cjs +16 -5
  23. package/dist/attachments/utils.cjs.map +1 -1
  24. package/dist/attachments/utils.d.cts +3 -1
  25. package/dist/attachments/utils.d.cts.map +1 -1
  26. package/dist/attachments/utils.d.mts +3 -1
  27. package/dist/attachments/utils.d.mts.map +1 -1
  28. package/dist/attachments/utils.mjs +16 -5
  29. package/dist/attachments/utils.mjs.map +1 -1
  30. package/dist/finalize-events.cjs +16 -0
  31. package/dist/finalize-events.cjs.map +1 -1
  32. package/dist/finalize-events.d.cts.map +1 -1
  33. package/dist/finalize-events.d.mts.map +1 -1
  34. package/dist/finalize-events.mjs +16 -0
  35. package/dist/finalize-events.mjs.map +1 -1
  36. package/dist/generative-ui/basic-functions.cjs +1 -1
  37. package/dist/generative-ui/basic-functions.cjs.map +1 -1
  38. package/dist/generative-ui/basic-functions.mjs +1 -1
  39. package/dist/generative-ui/basic-functions.mjs.map +1 -1
  40. package/dist/generative-ui/child-refs.cjs +3 -3
  41. package/dist/generative-ui/child-refs.cjs.map +1 -1
  42. package/dist/generative-ui/child-refs.d.cts.map +1 -1
  43. package/dist/generative-ui/child-refs.d.mts.map +1 -1
  44. package/dist/generative-ui/child-refs.mjs +3 -3
  45. package/dist/generative-ui/child-refs.mjs.map +1 -1
  46. package/dist/generative-ui/compact-schema.cjs +187 -0
  47. package/dist/generative-ui/compact-schema.cjs.map +1 -0
  48. package/dist/generative-ui/compact-schema.d.cts +55 -0
  49. package/dist/generative-ui/compact-schema.d.cts.map +1 -0
  50. package/dist/generative-ui/compact-schema.d.mts +55 -0
  51. package/dist/generative-ui/compact-schema.d.mts.map +1 -0
  52. package/dist/generative-ui/compact-schema.mjs +185 -0
  53. package/dist/generative-ui/compact-schema.mjs.map +1 -0
  54. package/dist/generative-ui/prompt-spec.cjs +225 -0
  55. package/dist/generative-ui/prompt-spec.cjs.map +1 -0
  56. package/dist/generative-ui/prompt-spec.d.cts +94 -0
  57. package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
  58. package/dist/generative-ui/prompt-spec.d.mts +94 -0
  59. package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
  60. package/dist/generative-ui/prompt-spec.mjs +220 -0
  61. package/dist/generative-ui/prompt-spec.mjs.map +1 -0
  62. package/dist/generative-ui/prompt.cjs +10 -36
  63. package/dist/generative-ui/prompt.cjs.map +1 -1
  64. package/dist/generative-ui/prompt.d.cts +2 -1
  65. package/dist/generative-ui/prompt.d.cts.map +1 -1
  66. package/dist/generative-ui/prompt.d.mts +2 -1
  67. package/dist/generative-ui/prompt.d.mts.map +1 -1
  68. package/dist/generative-ui/prompt.mjs +12 -38
  69. package/dist/generative-ui/prompt.mjs.map +1 -1
  70. package/dist/generative-ui/render-ui-args.cjs +1 -0
  71. package/dist/generative-ui/render-ui-args.cjs.map +1 -1
  72. package/dist/generative-ui/render-ui-args.d.cts.map +1 -1
  73. package/dist/generative-ui/render-ui-args.d.mts.map +1 -1
  74. package/dist/generative-ui/render-ui-args.mjs +1 -0
  75. package/dist/generative-ui/render-ui-args.mjs.map +1 -1
  76. package/dist/generative-ui/schema-render.cjs +242 -0
  77. package/dist/generative-ui/schema-render.cjs.map +1 -0
  78. package/dist/generative-ui/schema-render.d.cts +44 -0
  79. package/dist/generative-ui/schema-render.d.cts.map +1 -0
  80. package/dist/generative-ui/schema-render.d.mts +44 -0
  81. package/dist/generative-ui/schema-render.d.mts.map +1 -0
  82. package/dist/generative-ui/schema-render.mjs +239 -0
  83. package/dist/generative-ui/schema-render.mjs.map +1 -0
  84. package/dist/generative-ui/types.cjs +2 -2
  85. package/dist/generative-ui/types.cjs.map +1 -1
  86. package/dist/generative-ui/types.d.cts +7 -7
  87. package/dist/generative-ui/types.d.cts.map +1 -1
  88. package/dist/generative-ui/types.d.mts +7 -7
  89. package/dist/generative-ui/types.d.mts.map +1 -1
  90. package/dist/generative-ui/types.mjs +2 -2
  91. package/dist/generative-ui/types.mjs.map +1 -1
  92. package/dist/generative-ui/validate-operation.cjs +2 -2
  93. package/dist/generative-ui/validate-operation.cjs.map +1 -1
  94. package/dist/generative-ui/validate-operation.mjs +2 -2
  95. package/dist/generative-ui/validate-operation.mjs.map +1 -1
  96. package/dist/index.cjs +16 -15
  97. package/dist/index.cjs.map +1 -1
  98. package/dist/index.d.cts +10 -10
  99. package/dist/index.d.cts.map +1 -1
  100. package/dist/index.d.mts +10 -10
  101. package/dist/index.d.mts.map +1 -1
  102. package/dist/index.mjs +9 -8
  103. package/dist/index.mjs.map +1 -1
  104. package/dist/index.umd.js +866 -455
  105. package/dist/index.umd.js.map +1 -1
  106. package/dist/package.cjs +1 -1
  107. package/dist/package.mjs +1 -1
  108. package/dist/standard-schema.cjs +20 -7
  109. package/dist/standard-schema.cjs.map +1 -1
  110. package/dist/standard-schema.d.cts +15 -16
  111. package/dist/standard-schema.d.cts.map +1 -1
  112. package/dist/standard-schema.d.mts +15 -16
  113. package/dist/standard-schema.d.mts.map +1 -1
  114. package/dist/standard-schema.mjs +20 -8
  115. package/dist/standard-schema.mjs.map +1 -1
  116. package/dist/telemetry/lambda-client.cjs +1 -1
  117. package/dist/telemetry/lambda-client.cjs.map +1 -1
  118. package/dist/telemetry/lambda-client.d.cts.map +1 -1
  119. package/dist/telemetry/lambda-client.d.mts.map +1 -1
  120. package/dist/telemetry/lambda-client.mjs +1 -1
  121. package/dist/telemetry/lambda-client.mjs.map +1 -1
  122. package/dist/telemetry/telemetry-disabled.cjs +0 -5
  123. package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
  124. package/dist/telemetry/telemetry-disabled.d.cts +0 -5
  125. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
  126. package/dist/telemetry/telemetry-disabled.d.mts +0 -5
  127. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
  128. package/dist/telemetry/telemetry-disabled.mjs +0 -5
  129. package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
  130. package/dist/types/message.d.cts +1 -18
  131. package/dist/types/message.d.cts.map +1 -1
  132. package/dist/types/message.d.mts +1 -18
  133. package/dist/types/message.d.mts.map +1 -1
  134. package/dist/utils/errors.cjs +5 -42
  135. package/dist/utils/errors.cjs.map +1 -1
  136. package/dist/utils/errors.d.cts +16 -34
  137. package/dist/utils/errors.d.cts.map +1 -1
  138. package/dist/utils/errors.d.mts +16 -34
  139. package/dist/utils/errors.d.mts.map +1 -1
  140. package/dist/utils/errors.mjs +6 -41
  141. package/dist/utils/errors.mjs.map +1 -1
  142. package/dist/utils/index.cjs +0 -2
  143. package/dist/utils/index.cjs.map +1 -1
  144. package/dist/utils/index.d.cts +4 -6
  145. package/dist/utils/index.d.cts.map +1 -1
  146. package/dist/utils/index.d.mts +4 -6
  147. package/dist/utils/index.d.mts.map +1 -1
  148. package/dist/utils/index.mjs +4 -6
  149. package/dist/utils/index.mjs.map +1 -1
  150. package/dist/utils/inspector-visibility.cjs +25 -3
  151. package/dist/utils/inspector-visibility.cjs.map +1 -1
  152. package/dist/utils/inspector-visibility.d.cts +26 -3
  153. package/dist/utils/inspector-visibility.d.cts.map +1 -1
  154. package/dist/utils/inspector-visibility.d.mts +26 -3
  155. package/dist/utils/inspector-visibility.d.mts.map +1 -1
  156. package/dist/utils/inspector-visibility.mjs +25 -4
  157. package/dist/utils/inspector-visibility.mjs.map +1 -1
  158. package/dist/utils/json-schema.cjs +4 -79
  159. package/dist/utils/json-schema.cjs.map +1 -1
  160. package/dist/utils/json-schema.d.cts +1 -4
  161. package/dist/utils/json-schema.d.cts.map +1 -1
  162. package/dist/utils/json-schema.d.mts +1 -4
  163. package/dist/utils/json-schema.d.mts.map +1 -1
  164. package/dist/utils/json-schema.mjs +5 -78
  165. package/dist/utils/json-schema.mjs.map +1 -1
  166. package/dist/utils/random-id.cjs +13 -26
  167. package/dist/utils/random-id.cjs.map +1 -1
  168. package/dist/utils/random-id.d.cts +6 -3
  169. package/dist/utils/random-id.d.cts.map +1 -1
  170. package/dist/utils/random-id.d.mts +6 -3
  171. package/dist/utils/random-id.d.mts.map +1 -1
  172. package/dist/utils/random-id.mjs +14 -25
  173. package/dist/utils/random-id.mjs.map +1 -1
  174. package/package.json +10 -34
  175. package/scripts/verify-cjs-exports.cjs +1 -1
  176. package/src/__tests__/a2ui-envelope.test.ts +18 -13
  177. package/src/__tests__/a2ui-prompts.test.ts +47 -14
  178. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  179. package/src/__tests__/prompt-spec.test.ts +191 -0
  180. package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
  181. package/src/__tests__/schema-render.test.ts +245 -0
  182. package/src/__tests__/standard-schema.test.ts +61 -101
  183. package/src/a2ui-envelope.ts +7 -6
  184. package/src/a2ui-prompts.ts +47 -96
  185. package/src/attachments/__tests__/utils.test.ts +22 -0
  186. package/src/attachments/types.ts +1 -3
  187. package/src/attachments/utils.ts +23 -5
  188. package/src/finalize-events.ts +16 -0
  189. package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
  190. package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
  191. package/src/generative-ui/basic-functions.ts +1 -1
  192. package/src/generative-ui/child-refs.ts +5 -4
  193. package/src/generative-ui/compact-schema.ts +277 -0
  194. package/src/generative-ui/index.ts +3 -0
  195. package/src/generative-ui/prompt-spec.ts +335 -0
  196. package/src/generative-ui/prompt.ts +25 -75
  197. package/src/generative-ui/render-ui-args.ts +3 -0
  198. package/src/generative-ui/schema-render.ts +377 -0
  199. package/src/generative-ui/types.ts +10 -7
  200. package/src/generative-ui/validate-operation.ts +2 -2
  201. package/src/index.ts +3 -16
  202. package/src/standard-schema.ts +24 -27
  203. package/src/telemetry/lambda-client.ts +8 -3
  204. package/src/telemetry/model-host.test.ts +2 -5
  205. package/src/telemetry/telemetry-disabled.ts +0 -5
  206. package/src/types/message.ts +1 -19
  207. package/src/utils/__tests__/errors.test.ts +44 -0
  208. package/src/utils/__tests__/json-schema.test.ts +3 -479
  209. package/src/utils/__tests__/random-id.test.ts +37 -0
  210. package/src/utils/errors.ts +28 -85
  211. package/src/utils/index.ts +0 -2
  212. package/src/utils/inspector-visibility.test.ts +26 -0
  213. package/src/utils/inspector-visibility.ts +35 -3
  214. package/src/utils/json-schema.ts +5 -152
  215. package/src/utils/random-id.ts +17 -37
  216. package/tsconfig.json +3 -1
  217. package/tsdown.config.ts +2 -19
  218. package/dist/event-transforms/index.cjs +0 -15
  219. package/dist/event-transforms/index.d.cts +0 -4
  220. package/dist/event-transforms/index.d.mts +0 -4
  221. package/dist/event-transforms/index.mjs +0 -5
  222. package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
  223. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
  224. package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
  225. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
  226. package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
  227. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
  228. package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
  229. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
  230. package/dist/event-transforms/recorded-events.cjs +0 -59
  231. package/dist/event-transforms/recorded-events.cjs.map +0 -1
  232. package/dist/event-transforms/recorded-events.d.cts +0 -23
  233. package/dist/event-transforms/recorded-events.d.cts.map +0 -1
  234. package/dist/event-transforms/recorded-events.d.mts +0 -23
  235. package/dist/event-transforms/recorded-events.d.mts.map +0 -1
  236. package/dist/event-transforms/recorded-events.mjs +0 -58
  237. package/dist/event-transforms/recorded-events.mjs.map +0 -1
  238. package/dist/telemetry/events.d.cts +0 -72
  239. package/dist/telemetry/events.d.cts.map +0 -1
  240. package/dist/telemetry/events.d.mts +0 -72
  241. package/dist/telemetry/events.d.mts.map +0 -1
  242. package/dist/telemetry/index.cjs +0 -18
  243. package/dist/telemetry/index.d.cts +0 -5
  244. package/dist/telemetry/index.d.mts +0 -5
  245. package/dist/telemetry/index.mjs +0 -6
  246. package/dist/telemetry/telemetry-client.cjs +0 -165
  247. package/dist/telemetry/telemetry-client.cjs.map +0 -1
  248. package/dist/telemetry/telemetry-client.d.cts +0 -87
  249. package/dist/telemetry/telemetry-client.d.cts.map +0 -1
  250. package/dist/telemetry/telemetry-client.d.mts +0 -87
  251. package/dist/telemetry/telemetry-client.d.mts.map +0 -1
  252. package/dist/telemetry/telemetry-client.mjs +0 -164
  253. package/dist/telemetry/telemetry-client.mjs.map +0 -1
  254. package/dist/telemetry/utils.cjs +0 -14
  255. package/dist/telemetry/utils.cjs.map +0 -1
  256. package/dist/telemetry/utils.mjs +0 -13
  257. package/dist/telemetry/utils.mjs.map +0 -1
  258. package/dist/utils/conditions.cjs +0 -32
  259. package/dist/utils/conditions.cjs.map +0 -1
  260. package/dist/utils/conditions.d.cts +0 -31
  261. package/dist/utils/conditions.d.cts.map +0 -1
  262. package/dist/utils/conditions.d.mts +0 -31
  263. package/dist/utils/conditions.d.mts.map +0 -1
  264. package/dist/utils/conditions.mjs +0 -31
  265. package/dist/utils/conditions.mjs.map +0 -1
  266. package/dist/utils/console-styling.cjs +0 -91
  267. package/dist/utils/console-styling.cjs.map +0 -1
  268. package/dist/utils/console-styling.d.cts +0 -65
  269. package/dist/utils/console-styling.d.cts.map +0 -1
  270. package/dist/utils/console-styling.d.mts +0 -65
  271. package/dist/utils/console-styling.d.mts.map +0 -1
  272. package/dist/utils/console-styling.mjs +0 -85
  273. package/dist/utils/console-styling.mjs.map +0 -1
  274. package/src/__tests__/zod-regression.test.ts +0 -319
  275. package/src/event-transforms/index.ts +0 -5
  276. package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
  277. package/src/event-transforms/recorded-events.test.ts +0 -166
  278. package/src/event-transforms/recorded-events.ts +0 -74
  279. package/src/telemetry/events.ts +0 -68
  280. package/src/telemetry/index.ts +0 -9
  281. package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
  282. package/src/telemetry/telemetry-client.test.ts +0 -798
  283. package/src/telemetry/telemetry-client.ts +0 -328
  284. package/src/telemetry/utils.ts +0 -15
  285. package/src/utils/__tests__/conditions.test.ts +0 -161
  286. package/src/utils/conditions.ts +0 -116
  287. package/src/utils/console-styling.ts +0 -126
package/README.md CHANGED
@@ -206,17 +206,6 @@ attachment content part used by the React, Angular, and Vue chat components.
206
206
  It preserves the source and merges the filename into metadata, with explicit
207
207
  metadata taking precedence.
208
208
 
209
- The Node-only `@copilotkit/shared/event-transforms` entry exports
210
- `OpenGenerativeUIMiddleware`, the existing upstream `A2UIMiddleware`, and
211
- `transformRecordedEvents(input, events, options)`. The latter applies the same
212
- converters to one recorded, pre-middleware AG-UI run without executing tools or
213
- contacting an agent. Enable converters explicitly with `openGenerativeUI: true`
214
- and/or `a2ui: { ...originalRuntimeOptions }`. Pass the recorded input, including
215
- prior messages and catalog context, to preserve live conversion behavior.
216
-
217
- The result includes the original events and generated activities in runtime
218
- order. The caller owns persistence IDs, historical timestamps, and provenance.
219
- A2UI can generate random message IDs for synthetic tool results; an importer
220
- that needs deterministic IDs must assign them before saving. Do not process
221
- already transformed histories a second time. This entry does not include MCP
222
- execution or recreate runtime configuration absent from the recording.
209
+ `OpenGenerativeUIMiddleware`, `A2UIMiddleware`, and `transformRecordedEvents`
210
+ moved to `@copilotkit/runtime` in 2.0. The `@copilotkit/shared/event-transforms`
211
+ entry no longer exists.
@@ -72,7 +72,7 @@ function isExtensions(value) {
72
72
  return require_is_record.isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
73
73
  }
74
74
  function isEnvelope(value) {
75
- return require_is_record.isRecord(value) && isCapabilities(value["v1.0"]) && require_is_record.isRecord(value.metadata) && isExtensions(value.metadata.extensions);
75
+ return require_is_record.isRecord(value) && isCapabilities(value["1.0"]) && require_is_record.isRecord(value.metadata) && isExtensions(value.metadata.extensions);
76
76
  }
77
77
  /**
78
78
  * Reads the generative UI envelope from the `forwardedProps` of a run.
@@ -127,7 +127,7 @@ function readCopilotKitUIEnvelope(forwardedProps) {
127
127
  * ```
128
128
  */
129
129
  function envelopeToManifest(envelope) {
130
- const { supportedCatalogIds, inlineCatalogs } = envelope["v1.0"];
130
+ const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
131
131
  const catalogId = supportedCatalogIds[0];
132
132
  const catalog = inlineCatalogs?.find((entry) => entry.catalogId === catalogId);
133
133
  const extensions = envelope.metadata.extensions;
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-envelope.cjs","names":["isRecord","GENERATIVE_UI_MAX_TARGET_COMPONENTS","GENERATIVE_UI_MAX_SUMMARY_REJECTIONS","GENERATIVE_UI_MAX_REJECTION_LENGTH"],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"v1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"v1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"v1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"v1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"v1.0\"];\n const catalogId = supportedCatalogIds[0];\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,WACP,OACA,SAC4B;AAC5B,QAAOA,2BAAS,MAAM,IAAI,OAAO,OAAO,MAAM,CAAC,MAAM,QAAQ;;;AAI/D,SAAS,cAAc,OAAuD;AAC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;;;;;;AAsB3C,SAAgB,yBAAyB,gBAAyB;AAChE,KAAI,CAACA,2BAAS,eAAe,CAAE,QAAO;CACtC,MAAM,YAAY,eAAe;AACjC,KAAI,CAACA,2BAAS,UAAU,CAAE,QAAO;CACjC,MAAM,WAAW,UAAU;AAC3B,QAAO,WAAW,SAAS,GAAG,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B3C,SAAgB,mBAAmB,UAAgC;CACjE,MAAM,EAAE,qBAAqB,mBAAmB,SAAS;CACzD,MAAM,YAAY,oBAAoB;CACtC,MAAM,UAAU,gBAAgB,MAC7B,UAAU,MAAM,cAAc,UAChC;CACD,MAAM,aAAa,SAAS,SAAS;AASrC,QAAO;EAPL;EACA,YAAY;EACZ,YAAY,SAAS,cAAc,EAAE;EACrC,WAAW,SAAS,aAAa,EAAE;EACnC,SAAS,WAAW;EACpB,UAAU,WAAW;EAIrB,WAAW,WAAW;EACtB,aAAa,WAAW;EACxB,cAAc,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
1
+ {"version":3,"file":"a2ui-envelope.cjs","names":["isRecord","GENERATIVE_UI_MAX_TARGET_COMPONENTS","GENERATIVE_UI_MAX_SUMMARY_REJECTIONS","GENERATIVE_UI_MAX_REJECTION_LENGTH"],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"1.0\"];\n // `readCopilotKitUIEnvelope` only accepts a non-empty `supportedCatalogIds`.\n const catalogId = supportedCatalogIds[0]!;\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,WACP,OACA,SAC4B;AAC5B,QAAOA,2BAAS,MAAM,IAAI,OAAO,OAAO,MAAM,CAAC,MAAM,QAAQ;;;AAI/D,SAAS,cAAc,OAAuD;AAC5E,QACEA,2BAAS,MAAM,IACfA,2BAAS,MAAM,WAAW,IAC1B,iBAAiB,MAAM,YAAY;;AAIvC,SAAS,WAAW,OAAgD;AAClE,QAAO,UAAU,YAAY,UAAU;;;;;;AAOzC,SAAS,cAAc,OAAkD;AACvE,QACEA,2BAAS,MAAM,KACd,MAAM,eAAe,UAAaA,2BAAS,MAAM,WAAW,MAC5D,MAAM,aAAa,UACjB,MAAM,QAAQ,MAAM,SAAS,IAC5B,MAAM,SAAS,OAAO,SAAS,OAAO,SAAS,SAAS;;AAIhE,SAAS,oBACP,OACwC;AACxC,KACE,CAACA,2BAAS,MAAM,IAChB,CAAC,c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D,MAAM,aAAa,SAAS,SAAS;AASrC,QAAO;EAPL;EACA,YAAY;EACZ,YAAY,SAAS,cAAc,EAAE;EACrC,WAAW,SAAS,aAAa,EAAE;EACnC,SAAS,WAAW;EACpB,UAAU,WAAW;EAIrB,WAAW,WAAW;EACtB,aAAa,WAAW;EACxB,cAAc,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
@@ -8,7 +8,7 @@ declare const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;
8
8
  /** What the client renders and calls, and how the model must write UI. */
9
9
  interface CopilotKitUIEnvelope {
10
10
  /** The A2UI v1.0 renderer capabilities. */
11
- "v1.0": {
11
+ "1.0": {
12
12
  /**
13
13
  * The catalog that the client renders comes first, then the catalogs of
14
14
  * its `extends`. An operation can name any of them.
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-envelope.d.cts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,MAAA;IALwC;;;;IAUtC,mBAAA;IACA,cAAA,GAAiB,KAAA;MACf,SAAA;MACA,eAAA,SAEa;MAAb,UAAA,GAAa,MAAA,SAAe,6BAAA,GAEjB;MAAX,SAAA,EAAW,MAAA,SAAe,4BAAA,GAQA;MAN1B,YAAA;IAAA;EAAA;EAGJ,QAAA;IACE,UAAA;MAlBF,8BAoBI,iBAAA,SAA0B,6BAAA,EAd5B;MAgBE,oBAAA;MACA,kBAAA,EAAoB,oBAAA;MACpB,mBAAA,EAAqB,oBAAA,cAdrB;MAgBA,sBAAA;MAhB4B;;;;MAqB5B,iBAAA,GAAoB,iBAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;AA0L1B;;;;;AAmCA;;iBAnCgB,wBAAA,CAAyB,cAAA,YAAuB,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmChD,kBAAA,CAAmB,QAAA,EAAU,oBAAA"}
1
+ {"version":3,"file":"a2ui-envelope.d.cts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,KAAA;IALwC;;;;IAUtC,mBAAA;IACA,cAAA,GAAiB,KAAA;MACf,SAAA;MACA,eAAA,SAEa;MAAb,UAAA,GAAa,MAAA,SAAe,6BAAA,GAEjB;MAAX,SAAA,EAAW,MAAA,SAAe,4BAAA,GAQA;MAN1B,YAAA;IAAA;EAAA;EAGJ,QAAA;IACE,UAAA;MAlBF,8BAoBI,iBAAA,SAA0B,6BAAA,EAd5B;MAgBE,oBAAA;MACA,kBAAA,EAAoB,oBAAA;MACpB,mBAAA,EAAqB,oBAAA,cAdrB;MAgBA,sBAAA;MAhB4B;;;;MAqB5B,iBAAA,GAAoB,iBAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;AA0L1B;;;;;AAmCA;;iBAnCgB,wBAAA,CAAyB,cAAA,YAAuB,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmChD,kBAAA,CAAmB,QAAA,EAAU,oBAAA"}
@@ -8,7 +8,7 @@ declare const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;
8
8
  /** What the client renders and calls, and how the model must write UI. */
9
9
  interface CopilotKitUIEnvelope {
10
10
  /** The A2UI v1.0 renderer capabilities. */
11
- "v1.0": {
11
+ "1.0": {
12
12
  /**
13
13
  * The catalog that the client renders comes first, then the catalogs of
14
14
  * its `extends`. An operation can name any of them.
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-envelope.d.mts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,MAAA;IALwC;;;;IAUtC,mBAAA;IACA,cAAA,GAAiB,KAAA;MACf,SAAA;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7 @@ function isExtensions(value) {
72
72
  return isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
73
73
  }
74
74
  function isEnvelope(value) {
75
- return isRecord(value) && isCapabilities(value["v1.0"]) && isRecord(value.metadata) && isExtensions(value.metadata.extensions);
75
+ return isRecord(value) && isCapabilities(value["1.0"]) && isRecord(value.metadata) && isExtensions(value.metadata.extensions);
76
76
  }
77
77
  /**
78
78
  * Reads the generative UI envelope from the `forwardedProps` of a run.
@@ -127,7 +127,7 @@ function readCopilotKitUIEnvelope(forwardedProps) {
127
127
  * ```
128
128
  */
129
129
  function envelopeToManifest(envelope) {
130
- const { supportedCatalogIds, inlineCatalogs } = envelope["v1.0"];
130
+ const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
131
131
  const catalogId = supportedCatalogIds[0];
132
132
  const catalog = inlineCatalogs?.find((entry) => entry.catalogId === catalogId);
133
133
  const extensions = envelope.metadata.extensions;
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-envelope.mjs","names":[],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"v1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"v1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"v1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"v1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"v1.0\"];\n const catalogId = supportedCatalogIds[0];\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,WACP,OACA,SAC4B;AAC5B,QAAO,SAAS,MAAM,IAAI,OAAO,OAAO,MAAM,CAAC,MAAM,QAAQ;;;AAI/D,SAAS,cAAc,OAAuD;AAC5E,QACE,SAAS,MAAM,IACf,SAAS,MAAM,WAAW,IAC1B,iBAAiB,MAAM,YAAY;;AAIvC,SAAS,WAAW,OAAgD;AAClE,QAAO,UAAU,YAAY,UAAU;;;;;;AAOzC,SAAS,cAAc,OAAkD;AACvE,QACE,SAAS,MAAM,KACd,MAAM,eAAe,UAAa,SAAS,MAAM,WAAW,MAC5D,MAAM,aAAa,UACjB,MAAM,QAAQ,MAAM,SAAS,IAC5B,MAAM,SAAS,OAAO,SAAS,OAAO,SAAS,SAAS;;AAIhE,SAAS,oBACP,OACwC;AACxC,KACE,CAAC,SAAS,MAAM,IAChB,CAAC,cAAc,MAAM,MAAM,IAC3B,CAAC,iBAAiB,MAAM,YAAY,IACnC,MAAM,WAAW,UAAa,CAAC,WAAW,MAAM,QAAQ,cAAc,IACtE,MAAM,UAAU,UAAa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AIrB,WAAW,WAAW;EACtB,aAAa,WAAW;EACxB,cAAc,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
1
+ {"version":3,"file":"a2ui-envelope.mjs","names":[],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"1.0\"];\n // `readCopilotKitUIEnvelope` only accepts a non-empty `supportedCatalogIds`.\n const catalogId = supportedCatalogIds[0]!;\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QA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W,OAA+C;AACjE,QACE,SAAS,MAAM,IACf,eAAe,MAAM,OAAO,IAC5B,SAAS,MAAM,SAAS,IACxB,aAAa,MAAM,SAAS,WAAW;;;;;;;;;;;;;;;;;;;;AAsB3C,SAAgB,yBAAyB,gBAAyB;AAChE,KAAI,CAAC,SAAS,eAAe,CAAE,QAAO;CACtC,MAAM,YAAY,eAAe;AACjC,KAAI,CAAC,SAAS,UAAU,CAAE,QAAO;CACjC,MAAM,WAAW,UAAU;AAC3B,QAAO,WAAW,SAAS,GAAG,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B3C,SAAgB,mBAAmB,UAAgC;CACjE,MAAM,EAAE,qBAAqB,mBAAmB,SAAS;CAEzD,MAAM,YAAY,oBAAoB;CACtC,MAAM,UAAU,gBAAgB,MAC7B,UAAU,MAAM,cAAc,UAChC;CACD,MAAM,aAAa,SAAS,SAAS;AASrC,QAAO;EAPL;EACA,YAAY;EACZ,YAAY,SAAS,cAAc,EAAE;EACrC,WAAW,SAAS,aAAa,EAAE;EACnC,SAAS,WAAW;EACpB,UAAU,WAAW;EAIrB,WAAW,WAAW;EACtB,aAAa,WAAW;EACxB,cAAc,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
@@ -1,6 +1,6 @@
1
1
  const require_basic_functions = require('./generative-ui/basic-functions.cjs');
2
2
  const require_child_refs = require('./generative-ui/child-refs.cjs');
3
- const require_types = require('./generative-ui/types.cjs');
3
+ const require_prompt_spec = require('./generative-ui/prompt-spec.cjs');
4
4
 
5
5
  //#region src/a2ui-prompts.ts
6
6
  /**
@@ -116,12 +116,6 @@ Design principles:
116
116
  action context should reference the same paths to capture user input.
117
117
 
118
118
  Use the SAME surfaceId as the main surface. Match action names to button action event names.`;
119
- /**
120
- * When UI helps the user, for both transports: a light nudge to reach for UI
121
- * where it conveys the answer better than prose, and to stay in prose
122
- * otherwise.
123
- */
124
- const GENERATIVE_UI_WHEN_TO_SHOW = "Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.";
125
119
  /** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */
126
120
  const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = "Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.";
127
121
  /**
@@ -167,6 +161,7 @@ function generativeUIGuideFeatures(manifest) {
167
161
  return Object.values(node).some(hasChildList);
168
162
  };
169
163
  return {
164
+ components: Object.keys(manifest.components),
170
165
  functions: Object.keys(manifest.functions).some((name) => !require_basic_functions.isA2UIBasicFunction(name)),
171
166
  events: components.some((c) => Object.keys(c.events ?? {}).length > 0),
172
167
  templates: components.some((c) => Object.values(c.slots ?? {}).includes("multiple") || hasChildList(c.props)),
@@ -176,43 +171,18 @@ function generativeUIGuideFeatures(manifest) {
176
171
  })
177
172
  };
178
173
  }
179
- /** The first rules of every markdown guideline, before the optional groups. */
180
- const MARKDOWN_BASE_RULES = [
181
- "Write explanations as normal markdown prose outside the fences.",
182
- "Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
183
- "Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target has \"components\", its surfaces can use only those components.",
184
- "Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
185
- "Keep each operation whole on its line.",
186
- "Give every operation \"version\":\"v1.0\".",
187
- `Start a surface with one createSurface. Put all the initial data in "dataModel" and the "root" component in "components". Then write the children in updateComponents lines, so that they show while you write:
188
- \`\`\`a2ui
189
- {"version":"v1.0","createSurface":{"surfaceId":"plan-picker","dataModel":{ ...initial data... },"components":[{"id":"root","component":"<Name>","children":["seats","pick"]}]}}
190
- {"version":"v1.0","updateComponents":{"surfaceId":"plan-picker","components":[ ...the children... ]}}
191
- \`\`\``,
192
- "Keep \"dataModel\" flat: top-level keys such as \"seats\" or \"form\", never one wrapper object around everything. Check that every { and [ you open in a line is closed.",
193
- "Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
194
- "Use unique ids. Do not make cycles. A component cannot be its own child.",
195
- "Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
196
- "Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
197
- "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
198
- "Use only the components, props, events, and slots in the schema. A component with \"includesCommonProps\" also takes every prop in \"commonProps\".",
199
- "Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
200
- "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Use only the functions under \"functions\" in the schema. Write a literal when the value never changes.",
201
- "formatString interpolates ${...}: {\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} × ${formatCurrency(value: /price, currency: 'EUR')}\"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.",
202
- "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}. Inside formatString: ${formatCurrency(value: calc(expression: 'seats * 29', seats: /seats), currency: 'USD')}. The UI then follows the user's input with no round trip.",
203
- "For a computed list (chart data, template items) use series. Its description under \"functions\" in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.",
204
- "Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
205
- "To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".",
206
- "Set \"value\":null to delete the key at \"path\"."
207
- ];
208
- /** The last rules of every markdown guideline, after the optional groups. */
209
- const MARKDOWN_CLOSING_RULES = [
210
- "The schema lists the surfaces that already exist under \"surfaces\". \"dataModel\" holds the values that the user entered: read them, and do not write those paths. \"rejected\" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. \"status\":\"deleted\" means the surface is gone: never use its id again. \"status\":\"failed\" means its createSurface was rejected: send a corrected createSurface with that id.",
211
- "Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.",
212
- "Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
213
- "Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
214
- "Never wrap the whole reply in a fence."
215
- ];
174
+ /**
175
+ * Whether a guide line names only standard components (`GUIDE_COMPONENTS`,
176
+ * also in the plural) that the catalog has. With no catalog, every line fits.
177
+ */
178
+ function namesOnlyCatalogComponents(catalog) {
179
+ if (!catalog) return () => true;
180
+ const has = new Set(catalog);
181
+ return (line) => (line.match(/\b[A-Z][A-Za-z0-9]*\b/g) ?? []).every((word) => {
182
+ const name = !require_prompt_spec.GUIDE_COMPONENTS.has(word) && word.endsWith("s") ? word.slice(0, -1) : word;
183
+ return !require_prompt_spec.GUIDE_COMPONENTS.has(name) || has.has(name);
184
+ });
185
+ }
216
186
  /**
217
187
  * Builds the markdown-transport guideline. The model writes A2UI v1.0
218
188
  * operations inside ```a2ui fences between normal markdown prose. The rules
@@ -220,25 +190,15 @@ const MARKDOWN_CLOSING_RULES = [
220
190
  * none of them, so the guideline stays small.
221
191
  *
222
192
  * @param features - The optional rule groups to include. Defaults to all.
193
+ * @param spec - The wording. Defaults to the prompts that ship.
223
194
  * @returns The guideline text, one rule per line.
224
195
  */
225
- function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES) {
226
- const { functions, events, templates, checks } = features;
227
- const rules = [...MARKDOWN_BASE_RULES];
228
- if (events) rules.push("Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.", functions ? "Use {\"functionCall\": ...} to run a function in the browser when the user clicks: an app function from the schema, or openUrl: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call." : "Use {\"functionCall\": ...} to open a URL when the user clicks: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call.", "Use {\"event\": ...} to send the interaction back to you as a user message. Put the text of that message in \"userMessage\": {\"event\":{\"name\":\"choose\",\"userMessage\":\"Show me the Team plan\"}}. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".", "To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.", "A button or other event prop without an event or functionCall does nothing.");
229
- if (checks) rules.push("Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email; a condition can also be a boolean {\"@path\"}. A failed check shows the message under the input and disables a Button that has the same checks.");
230
- rules.push("A prop typed componentId takes the id of another component, and a childList takes ids [\"a\",\"b\"]: \"child\":\"card\", \"children\":[\"a\",\"b\"], \"tabs\":[{\"title\":\"Specs\",\"child\":\"specs\"}].");
231
- if (templates) rules.push("To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.", "Inside a template, paths are relative to the item (\"name\", not \"/name\").", "Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}.");
232
- rules.push("Updating a component replaces all of its props. Send every prop again.", "To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.", "Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.");
233
- if (functions && require_types.GENERATIVE_UI_AGENT_FUNCTION_CALLS) rules.push("To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.", "Give every callRendererFunction a new functionCallId. Call only a function from the schema with \"callers\": \"UI or agent\" or \"agent only\"; a function without \"callers\" is for the UI only. A function with \"callers\": \"agent only\" is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.", "Do not guess the result of a callRendererFunction. Wait for the developer message.");
234
- rules.push(...MARKDOWN_CLOSING_RULES);
235
- return `You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.
236
-
237
- ${GENERATIVE_UI_WHEN_TO_SHOW}
238
-
239
- RULES
240
- ${rules.map((rule) => `- ${rule}`).join("\n")}
241
- `;
196
+ function buildGenerativeUIMarkdownGuidelines(features = ALL_GENERATIVE_UI_GUIDE_FEATURES, spec = require_prompt_spec.defaultGenerativeUIPromptSpec()) {
197
+ const { intro, rules } = spec.markdown;
198
+ const fits = namesOnlyCatalogComponents(features.components);
199
+ const selected = require_prompt_spec.selectPromptItems(rules, require_prompt_spec.generativeUIPromptFeatures(features)).filter(fits);
200
+ const whenToShow = spec.markdown.whenToShow.split("\n").filter(fits).join("\n");
201
+ return `${intro}\n\n${whenToShow ? `${whenToShow}\n\n` : ""}RULES\n${selected.map((rule) => `- ${rule}`).join("\n")}\n`;
242
202
  }
243
203
  /**
244
204
  * The markdown-transport guideline with every rule group. A run sends
@@ -253,7 +213,6 @@ exports.ALL_GENERATIVE_UI_GUIDE_FEATURES = ALL_GENERATIVE_UI_GUIDE_FEATURES;
253
213
  exports.GENERATIVE_UI_MARKDOWN_GUIDELINES = GENERATIVE_UI_MARKDOWN_GUIDELINES;
254
214
  exports.GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION = GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION;
255
215
  exports.GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION = GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION;
256
- exports.GENERATIVE_UI_WHEN_TO_SHOW = GENERATIVE_UI_WHEN_TO_SHOW;
257
216
  exports.buildGenerativeUIMarkdownGuidelines = buildGenerativeUIMarkdownGuidelines;
258
217
  exports.generativeUIGuideFeatures = generativeUIGuideFeatures;
259
218
  //# sourceMappingURL=a2ui-prompts.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-prompts.cjs","names":["A2UI_CHILD_LIST_REF","isA2UIBasicFunction","GENERATIVE_UI_AGENT_FUNCTION_CALLS"],"sources":["../src/a2ui-prompts.ts"],"sourcesContent":["import { isA2UIBasicFunction } from \"./generative-ui/basic-functions\";\nimport { A2UI_CHILD_LIST_REF } from \"./generative-ui/child-refs\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./generative-ui/types\";\nimport type { GenerativeUIManifest } from \"./generative-ui/types\";\n/**\n * Default A2UI generation and design guideline prompts.\n *\n * These are the canonical prompt fragments that instruct an LLM how to call\n * the render_a2ui tool, how to bind data, and how to style surfaces.\n */\n\n/**\n * Generation guidelines — protocol rules, tool arguments, path rules,\n * data model format, and form/two-way-binding instructions.\n */\nexport const A2UI_DEFAULT_GENERATION_GUIDELINES = `\\\nGenerate A2UI v0.9 JSON.\n\n## A2UI Protocol Instructions\n\nA2UI (Agent to UI) is a protocol for rendering rich UI surfaces from agent responses.\n\nCRITICAL: You MUST call the render_a2ui tool with ALL of these arguments:\n- surfaceId: A unique ID for the surface (e.g. \"product-comparison\")\n- components: REQUIRED — the A2UI component array. NEVER omit this. Only use\n components listed in the Available Components schema provided as context.\n- data: OPTIONAL — a JSON object written to the root of the surface data model.\n Use for pre-filling form values or providing data for path-bound components.\n- every component must have the \"component\" field specifying the component type.\n ONLY use component names from the Available Components schema — do NOT invent\n component names or use names not in the schema.\n\nCOMPONENT ID RULES:\n- Exactly one component MUST have id=\"root\". This is the surface's entry\n point — the renderer begins at \"root\" and walks the child/children tree\n from there. Every other component must be reachable from \"root\". If no\n component has id=\"root\", the surface renders an empty loading placeholder\n and none of your components will be shown.\n- Every component ID must be unique within the surface.\n- A component MUST NOT reference itself as child/children. This causes a\n circular dependency error. For example, if a component has id=\"avatar\",\n its child must be a DIFFERENT id (e.g. \"avatar-img\"), never \"avatar\".\n- The child/children tree must be a DAG — no cycles allowed.\n\nREPEATING CONTENT (TEMPLATES):\nTo repeat a component for each item in an array, use the structural children format:\n children: { componentId: \"card-id\", path: \"/items\" }\nThis tells the renderer to create one instance of \"card-id\" per item in the \"/items\" array.\n\nPATH RULES FOR TEMPLATES:\nComponents inside a repeating template use RELATIVE paths (no leading slash).\nThe path is resolved relative to each array item automatically.\nIf a container has children: { componentId: \"card\", path: \"/items\" } and each item\nhas a key \"name\", use { \"path\": \"name\" } (NO leading slash — relative to item).\nCRITICAL: Do NOT use \"/name\" (absolute) inside templates — use \"name\" (relative).\nThe container's path (\"/items\") uses a leading slash (absolute), but all\ncomponents INSIDE the template use paths WITHOUT leading slash.\n\nCOMPONENT VALUES — DEFAULT RULE:\nUse inline literal values for ALL component properties. Pass strings, numbers,\narrays, and objects directly on the component. Do NOT use { \"path\": \"...\" }\nobjects unless the property's schema explicitly allows it (see exception below).\nCRITICAL: USING { \"path\": \"...\" } ON A PROPERTY THAT DOES NOT DECLARE PATH\nSUPPORT IN ITS SCHEMA WILL CAUSE A RUNTIME CRASH AND BREAK THE ENTIRE UI.\nALWAYS CHECK THE COMPONENT SCHEMA FIRST — IF THE PROPERTY ONLY ACCEPTS A\nPLAIN TYPE, YOU MUST USE A LITERAL VALUE.\nVERY IMPORTANT: THE APPLICATION WILL BREAK IF YOU DO NOT FOLLOW THIS RULE!\n\nFor example, a chart's \"data\" must always be an inline array:\n \"data\": [{\"label\": \"Jan\", \"value\": 100}, {\"label\": \"Feb\", \"value\": 200}]\nA metric's \"value\" must always be an inline string:\n \"value\": \"$1,200\"\n\nPATH BINDING EXCEPTION — SCHEMA-DRIVEN:\nA few properties accept { \"path\": \"/some/path\" } as an alternative to a literal\nvalue. You can identify these in the Available Components schema: the property\nwill list BOTH a literal type AND an object-with-path option. If a property only\nshows a single type (string, number, array, etc.), it does NOT support path\nbinding — use a literal value only.\n\nPath binding is typically used for editable form inputs so the client can write\nuser input back to the data model. When building forms:\n- Bind input \"value\" to a data model path: \"value\": { \"path\": \"/form/name\" }\n- Pre-fill via the \"data\" tool argument: \"data\": { \"form\": { \"name\": \"Alice\" } }\n- Capture values on submit via button action context:\n \"action\": { \"event\": { \"name\": \"submit\", \"context\": { \"name\": { \"path\": \"/form/name\" } } } }\n\nREPEATING CONTENT uses a structural children format (not the same as value binding):\n children: { componentId: \"card-id\", path: \"/items\" }\nComponents inside templates use RELATIVE paths (no leading slash): { \"path\": \"name\" }.`;\n\n/**\n * Design guidelines — visual design rules, component hierarchy tips,\n * and action handler patterns.\n */\nexport const A2UI_DEFAULT_DESIGN_GUIDELINES = `\\\nCreate polished, visually appealing interfaces. ONLY use components listed in the\nAvailable Components schema — do NOT use component names that are not in the schema.\n\nDesign principles:\n- Create clear visual hierarchy within cards and layouts.\n- Keep cards clean — avoid clutter. Whitespace is good.\n- Use consistent surfaceIds (lowercase, hyphenated).\n- NEVER use the same ID for a component and its child — this creates a\n circular dependency. E.g. if id=\"avatar\", child must NOT be \"avatar\".\n- For side-by-side comparisons, use a container with structural children\n (children: { componentId, path }) to repeat a card template per data item.\n- Include images when relevant (logos, icons, product photos):\n - Prefer company logos via Google favicons: https://www.google.com/s2/favicons?domain=example.com&sz=128\n - Do NOT invent Unsplash photo-IDs — they will 404. Only use real, known URLs.\n- For buttons: action MUST use this exact nested format:\n \"action\": { \"event\": { \"name\": \"myAction\", \"context\": { \"key\": \"value\" } } }\n The \"event\" key holds an OBJECT with \"name\" (required) and \"context\" (optional).\n Do NOT use a flat format like {\"event\": \"name\"} — \"event\" must be an object.\n- For forms: check the component schema — if an input's \"value\" property\n supports path binding, use it for editable fields. The submit button's\n action context should reference the same paths to capture user input.\n\nUse the SAME surfaceId as the main surface. Match action names to button action event names.`;\n\n/**\n * When UI helps the user, for both transports: a light nudge to reach for UI\n * where it conveys the answer better than prose, and to stay in prose\n * otherwise.\n */\nexport const GENERATIVE_UI_WHEN_TO_SHOW =\n \"Show UI when it conveys the answer better than prose: to illustrate a concept (a diagram, a chart of how something changes), to compare options side by side, to let the user explore or adjust values, or to collect input. A small, focused surface next to your explanation often lands better than a long description. Reply in prose alone for a quick fact, a short answer, or conversation, and never add UI only as decoration.\";\n\n/** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */\nexport const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION =\n \"Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.\";\n\n/**\n * Description of the context entry that carries the compact component schema\n * in the markdown transport.\n *\n * It must not equal `A2UI_SCHEMA_CONTEXT_DESCRIPTION` (the key that\n * `@ag-ui/a2ui-middleware` stamps for tool mode). The LangGraph and Strands\n * adapters find that exact string and move the entry into\n * `state[\"ag-ui\"][\"a2ui_schema\"]` for the `render_a2ui` tool, so it never\n * gets to the system prompt. The markdown transport has no tool, so the\n * schema must stay ordinary context that the model reads as App Context.\n */\nexport const GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION =\n \"Generative UI component schema: the components, props, events, slots, functions, and targets that ```a2ui code fences can use, and the surfaces that already exist.\";\n\n/** Which optional parts of A2UI a manifest uses. The guides leave out the rules for the others. */\nexport interface GenerativeUIGuideFeatures {\n /** A function is mounted: function calls and callRendererFunction. */\n functions: boolean;\n /** A component has an event prop. */\n events: boolean;\n /** A component has a \"multiple\" slot, which takes templates and @index. */\n templates: boolean;\n /** A component has a \"checks\" prop: validation rules on inputs. */\n checks: boolean;\n}\n\n/** Every optional rule group. Use it when the manifest is not known. */\nexport const ALL_GENERATIVE_UI_GUIDE_FEATURES: GenerativeUIGuideFeatures = {\n functions: true,\n events: true,\n templates: true,\n checks: true,\n};\n\n/**\n * The optional parts of A2UI that a manifest uses, so that a guide sends only\n * the rules that the model can apply.\n *\n * @param manifest - The components and the mounted functions of a run.\n * @returns Which optional rule groups the guides include.\n *\n * @example\n * ```ts\n * const guide = buildGenerativeUIMarkdownGuidelines(\n * generativeUIGuideFeatures(manifest),\n * );\n * ```\n */\nexport function generativeUIGuideFeatures(\n manifest: Pick<GenerativeUIManifest, \"components\" | \"functions\">,\n): GenerativeUIGuideFeatures {\n const components = Object.values(manifest.components);\n const hasChildList = (schema: unknown): boolean => {\n if (Array.isArray(schema)) return schema.some(hasChildList);\n if (typeof schema !== \"object\" || schema === null) return false;\n const node = schema as Record<string, unknown>;\n if (node.$ref === A2UI_CHILD_LIST_REF) return true;\n return Object.values(node).some(hasChildList);\n };\n return {\n // App functions only: the built-in ones are always there and have\n // their own rules.\n functions: Object.keys(manifest.functions).some(\n (name) => !isA2UIBasicFunction(name),\n ),\n events: components.some((c) => Object.keys(c.events ?? {}).length > 0),\n templates: components.some(\n (c) =>\n Object.values(c.slots ?? {}).includes(\"multiple\") ||\n hasChildList(c.props),\n ),\n checks: components.some((c) => {\n const properties = c.props.properties;\n return (\n typeof properties === \"object\" &&\n properties !== null &&\n Object.prototype.hasOwnProperty.call(properties, \"checks\")\n );\n }),\n };\n}\n\n/** The first rules of every markdown guideline, before the optional groups. */\nconst MARKDOWN_BASE_RULES = [\n \"Write explanations as normal markdown prose outside the fences.\",\n \"Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.\",\n 'Open a fence with ```a2ui target=<id> to show the surface in a named target. Use only target ids from the schema. When a target has \"components\", its surfaces can use only those components.',\n \"Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.\",\n \"Keep each operation whole on its line.\",\n 'Give every operation \"version\":\"v1.0\".',\n `Start a surface with one createSurface. Put all the initial data in \"dataModel\" and the \"root\" component in \"components\". Then write the children in updateComponents lines, so that they show while you write:\n \\`\\`\\`a2ui\n {\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"plan-picker\",\"dataModel\":{ ...initial data... },\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"seats\",\"pick\"]}]}}\n {\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"plan-picker\",\"components\":[ ...the children... ]}}\n \\`\\`\\``,\n 'Keep \"dataModel\" flat: top-level keys such as \"seats\" or \"form\", never one wrapper object around everything. Check that every { and [ you open in a line is closed.',\n 'Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.',\n \"Use unique ids. Do not make cycles. A component cannot be its own child.\",\n 'Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.',\n 'Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.',\n 'A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.',\n 'Use only the components, props, events, and slots in the schema. A component with \"includesCommonProps\" also takes every prop in \"commonProps\".',\n 'Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.',\n 'A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Use only the functions under \"functions\" in the schema. Write a literal when the value never changes.',\n 'formatString interpolates ${...}: {\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} × ${formatCurrency(value: /price, currency: \\'EUR\\')}\"}}. Inside ${...}, a path has no quotes, a string has single quotes, and a function takes named args.',\n '${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}. Inside formatString: ${formatCurrency(value: calc(expression: \\'seats * 29\\', seats: /seats), currency: \\'USD\\')}. The UI then follows the user\\'s input with no round trip.',\n 'For a computed list (chart data, template items) use series. Its description under \"functions\" in the schema gives the rules and an example. Bind the \"data\" of a Chart or the \"items\" of a List to it; a template path stays a literal path.',\n 'Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user\\'s input goes to that path.',\n 'To change data, write updateDataModel with a \"path\" and a \"value\": {\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"plan-picker\",\"path\":\"/seats\",\"value\":12}}. Always give \"value\".',\n 'Set \"value\":null to delete the key at \"path\".',\n];\n\n/** The last rules of every markdown guideline, after the optional groups. */\nconst MARKDOWN_CLOSING_RULES = [\n 'The schema lists the surfaces that already exist under \"surfaces\". \"dataModel\" holds the values that the user entered: read them, and do not write those paths. \"rejected\" lists operations that the client dropped: send corrected operations in a new fence for that surfaceId. \"status\":\"deleted\" means the surface is gone: never use its id again. \"status\":\"failed\" means its createSurface was rejected: send a corrected createSurface with that id.',\n \"Never make a surface that is only prose. Write headings, paragraphs, lists of text, intros, and summaries as markdown outside the fences, also between two fences.\",\n \"Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.\",\n \"Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.\",\n \"Never wrap the whole reply in a fence.\",\n];\n\n/**\n * Builds the markdown-transport guideline. The model writes A2UI v1.0\n * operations inside ```a2ui fences between normal markdown prose. The rules\n * for functions, events, and templates are left out when the manifest has\n * none of them, so the guideline stays small.\n *\n * @param features - The optional rule groups to include. Defaults to all.\n * @returns The guideline text, one rule per line.\n */\nexport function buildGenerativeUIMarkdownGuidelines(\n features: GenerativeUIGuideFeatures = ALL_GENERATIVE_UI_GUIDE_FEATURES,\n) {\n const { functions, events, templates, checks } = features;\n const rules = [...MARKDOWN_BASE_RULES];\n if (events) {\n rules.push(\n 'Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.',\n functions\n ? 'Use {\"functionCall\": ...} to run a function in the browser when the user clicks: an app function from the schema, or openUrl: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call.'\n : 'Use {\"functionCall\": ...} to open a URL when the user clicks: {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"https://example.com\"}}}. You are not told about the call.',\n 'Use {\"event\": ...} to send the interaction back to you as a user message. Put the text of that message in \"userMessage\": {\"event\":{\"name\":\"choose\",\"userMessage\":\"Show me the Team plan\"}}. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".',\n 'To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.',\n \"A button or other event prop without an event or functionCall does nothing.\",\n );\n }\n if (checks) {\n rules.push(\n 'Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email; a condition can also be a boolean {\"@path\"}. A failed check shows the message under the input and disables a Button that has the same checks.',\n );\n }\n rules.push(\n 'A prop typed componentId takes the id of another component, and a childList takes ids [\"a\",\"b\"]: \"child\":\"card\", \"children\":[\"a\",\"b\"], \"tabs\":[{\"title\":\"Specs\",\"child\":\"specs\"}].',\n );\n if (templates) {\n rules.push(\n 'To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.',\n 'Inside a template, paths are relative to the item (\"name\", not \"/name\").',\n 'Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}.',\n );\n }\n rules.push(\n \"Updating a component replaces all of its props. Send every prop again.\",\n \"To change a surface in this reply, write another fence with the same surfaceId. Do not send createSurface again. The surface changes where it already is. A surface in a target can also be changed from a later reply; a chat surface cannot, because the chat is a transcript: a later reply with the same surfaceId makes a new surface.\",\n \"Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.\",\n );\n if (functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS) {\n rules.push(\n 'To run an app function now, with no click, write a callRendererFunction line in a fence: {\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}. It needs no surface.',\n 'Give every callRendererFunction a new functionCallId. Call only a function from the schema with \"callers\": \"UI or agent\" or \"agent only\"; a function without \"callers\" is for the UI only. A function with \"callers\": \"agent only\" is only for callRendererFunction: do not bind an event to it.',\n 'The result of a callRendererFunction comes back to you as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Then you get a new turn.',\n \"Do not guess the result of a callRendererFunction. Wait for the developer message.\",\n );\n }\n rules.push(...MARKDOWN_CLOSING_RULES);\n return `You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.\n\n${GENERATIVE_UI_WHEN_TO_SHOW}\n\nRULES\n${rules.map((rule) => `- ${rule}`).join(\"\\n\")}\n`;\n}\n\n/**\n * The markdown-transport guideline with every rule group. A run sends\n * `buildGenerativeUIMarkdownGuidelines` for its own manifest instead.\n */\nexport const GENERATIVE_UI_MARKDOWN_GUIDELINES =\n buildGenerativeUIMarkdownGuidelines();\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFlD,MAAa,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B9C,MAAa,6BACX;;AAGF,MAAa,gDACX;;;;;;;;;;;;AAaF,MAAa,oDACX;;AAeF,MAAa,mCAA8D;CACzE,WAAW;CACX,QAAQ;CACR,WAAW;CACX,QAAQ;CACT;;;;;;;;;;;;;;;AAgBD,SAAgB,0BACd,UAC2B;CAC3B,MAAM,aAAa,OAAO,OAAO,SAAS,WAAW;CACrD,MAAM,gBAAgB,WAA6B;AACjD,MAAI,MAAM,QAAQ,OAAO,CAAE,QAAO,OAAO,KAAK,aAAa;AAC3D,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;EAC1D,MAAM,OAAO;AACb,MAAI,KAAK,SAASA,uCAAqB,QAAO;AAC9C,SAAO,OAAO,OAAO,KAAK,CAAC,KAAK,aAAa;;AAE/C,QAAO;EAGL,WAAW,OAAO,KAAK,SAAS,UAAU,CAAC,MACxC,SAAS,CAACC,4CAAoB,KAAK,CACrC;EACD,QAAQ,WAAW,MAAM,MAAM,OAAO,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,SAAS,EAAE;EACtE,WAAW,WAAW,MACnB,MACC,OAAO,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,WAAW,IACjD,aAAa,EAAE,MAAM,CACxB;EACD,QAAQ,WAAW,MAAM,MAAM;GAC7B,MAAM,aAAa,EAAE,MAAM;AAC3B,UACE,OAAO,eAAe,YACtB,eAAe,QACf,OAAO,UAAU,eAAe,KAAK,YAAY,SAAS;IAE5D;EACH;;;AAIH,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;;;;;CAKA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAM,yBAAyB;CAC7B;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;AAWD,SAAgB,oCACd,WAAsC,kCACtC;CACA,MAAM,EAAE,WAAW,QAAQ,WAAW,WAAW;CACjD,MAAM,QAAQ,CAAC,GAAG,oBAAoB;AACtC,KAAI,OACF,OAAM,KACJ,sNACA,YACI,4PACA,2LACJ,ySACA,sHACA,8EACD;AAEH,KAAI,OACF,OAAM,KACJ,uXACD;AAEH,OAAM,KACJ,6MACD;AACD,KAAI,UACF,OAAM,KACJ,2IACA,gFACA,2JACD;AAEH,OAAM,KACJ,0EACA,+UACA,4GACD;AACD,KAAI,aAAaC,iDACf,OAAM,KACJ,kQACA,gTACA,wQACA,qFACD;AAEH,OAAM,KAAK,GAAG,uBAAuB;AACrC,QAAO;;EAEP,2BAA2B;;;EAG3B,MAAM,KAAK,SAAS,KAAK,OAAO,CAAC,KAAK,KAAK,CAAC;;;;;;;AAQ9C,MAAa,oCACX,qCAAqC"}
1
+ {"version":3,"file":"a2ui-prompts.cjs","names":["A2UI_CHILD_LIST_REF","isA2UIBasicFunction","GUIDE_COMPONENTS","defaultGenerativeUIPromptSpec","selectPromptItems","generativeUIPromptFeatures"],"sources":["../src/a2ui-prompts.ts"],"sourcesContent":["import { isA2UIBasicFunction } from \"./generative-ui/basic-functions\";\nimport { A2UI_CHILD_LIST_REF } from \"./generative-ui/child-refs\";\nimport type { GenerativeUIManifest } from \"./generative-ui/types\";\nimport {\n defaultGenerativeUIPromptSpec,\n GUIDE_COMPONENTS,\n generativeUIPromptFeatures,\n selectPromptItems,\n} from \"./generative-ui/prompt-spec\";\nimport type { GenerativeUIPromptSpec } from \"./generative-ui/prompt-spec\";\nexport {\n GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW,\n GENERATIVE_UI_WHEN_TO_SHOW,\n} from \"./generative-ui/prompt-spec\";\n/**\n * Default A2UI generation and design guideline prompts.\n *\n * These are the canonical prompt fragments that instruct an LLM how to call\n * the render_a2ui tool, how to bind data, and how to style surfaces.\n */\n\n/**\n * Generation guidelines — protocol rules, tool arguments, path rules,\n * data model format, and form/two-way-binding instructions.\n */\nexport const A2UI_DEFAULT_GENERATION_GUIDELINES = `\\\nGenerate A2UI v0.9 JSON.\n\n## A2UI Protocol Instructions\n\nA2UI (Agent to UI) is a protocol for rendering rich UI surfaces from agent responses.\n\nCRITICAL: You MUST call the render_a2ui tool with ALL of these arguments:\n- surfaceId: A unique ID for the surface (e.g. \"product-comparison\")\n- components: REQUIRED — the A2UI component array. NEVER omit this. Only use\n components listed in the Available Components schema provided as context.\n- data: OPTIONAL — a JSON object written to the root of the surface data model.\n Use for pre-filling form values or providing data for path-bound components.\n- every component must have the \"component\" field specifying the component type.\n ONLY use component names from the Available Components schema — do NOT invent\n component names or use names not in the schema.\n\nCOMPONENT ID RULES:\n- Exactly one component MUST have id=\"root\". This is the surface's entry\n point — the renderer begins at \"root\" and walks the child/children tree\n from there. Every other component must be reachable from \"root\". If no\n component has id=\"root\", the surface renders an empty loading placeholder\n and none of your components will be shown.\n- Every component ID must be unique within the surface.\n- A component MUST NOT reference itself as child/children. This causes a\n circular dependency error. For example, if a component has id=\"avatar\",\n its child must be a DIFFERENT id (e.g. \"avatar-img\"), never \"avatar\".\n- The child/children tree must be a DAG — no cycles allowed.\n\nREPEATING CONTENT (TEMPLATES):\nTo repeat a component for each item in an array, use the structural children format:\n children: { componentId: \"card-id\", path: \"/items\" }\nThis tells the renderer to create one instance of \"card-id\" per item in the \"/items\" array.\n\nPATH RULES FOR TEMPLATES:\nComponents inside a repeating template use RELATIVE paths (no leading slash).\nThe path is resolved relative to each array item automatically.\nIf a container has children: { componentId: \"card\", path: \"/items\" } and each item\nhas a key \"name\", use { \"path\": \"name\" } (NO leading slash — relative to item).\nCRITICAL: Do NOT use \"/name\" (absolute) inside templates — use \"name\" (relative).\nThe container's path (\"/items\") uses a leading slash (absolute), but all\ncomponents INSIDE the template use paths WITHOUT leading slash.\n\nCOMPONENT VALUES — DEFAULT RULE:\nUse inline literal values for ALL component properties. Pass strings, numbers,\narrays, and objects directly on the component. Do NOT use { \"path\": \"...\" }\nobjects unless the property's schema explicitly allows it (see exception below).\nCRITICAL: USING { \"path\": \"...\" } ON A PROPERTY THAT DOES NOT DECLARE PATH\nSUPPORT IN ITS SCHEMA WILL CAUSE A RUNTIME CRASH AND BREAK THE ENTIRE UI.\nALWAYS CHECK THE COMPONENT SCHEMA FIRST — IF THE PROPERTY ONLY ACCEPTS A\nPLAIN TYPE, YOU MUST USE A LITERAL VALUE.\nVERY IMPORTANT: THE APPLICATION WILL BREAK IF YOU DO NOT FOLLOW THIS RULE!\n\nFor example, a chart's \"data\" must always be an inline array:\n \"data\": [{\"label\": \"Jan\", \"value\": 100}, {\"label\": \"Feb\", \"value\": 200}]\nA metric's \"value\" must always be an inline string:\n \"value\": \"$1,200\"\n\nPATH BINDING EXCEPTION — SCHEMA-DRIVEN:\nA few properties accept { \"path\": \"/some/path\" } as an alternative to a literal\nvalue. You can identify these in the Available Components schema: the property\nwill list BOTH a literal type AND an object-with-path option. If a property only\nshows a single type (string, number, array, etc.), it does NOT support path\nbinding — use a literal value only.\n\nPath binding is typically used for editable form inputs so the client can write\nuser input back to the data model. When building forms:\n- Bind input \"value\" to a data model path: \"value\": { \"path\": \"/form/name\" }\n- Pre-fill via the \"data\" tool argument: \"data\": { \"form\": { \"name\": \"Alice\" } }\n- Capture values on submit via button action context:\n \"action\": { \"event\": { \"name\": \"submit\", \"context\": { \"name\": { \"path\": \"/form/name\" } } } }\n\nREPEATING CONTENT uses a structural children format (not the same as value binding):\n children: { componentId: \"card-id\", path: \"/items\" }\nComponents inside templates use RELATIVE paths (no leading slash): { \"path\": \"name\" }.`;\n\n/**\n * Design guidelines — visual design rules, component hierarchy tips,\n * and action handler patterns.\n */\nexport const A2UI_DEFAULT_DESIGN_GUIDELINES = `\\\nCreate polished, visually appealing interfaces. ONLY use components listed in the\nAvailable Components schema — do NOT use component names that are not in the schema.\n\nDesign principles:\n- Create clear visual hierarchy within cards and layouts.\n- Keep cards clean — avoid clutter. Whitespace is good.\n- Use consistent surfaceIds (lowercase, hyphenated).\n- NEVER use the same ID for a component and its child — this creates a\n circular dependency. E.g. if id=\"avatar\", child must NOT be \"avatar\".\n- For side-by-side comparisons, use a container with structural children\n (children: { componentId, path }) to repeat a card template per data item.\n- Include images when relevant (logos, icons, product photos):\n - Prefer company logos via Google favicons: https://www.google.com/s2/favicons?domain=example.com&sz=128\n - Do NOT invent Unsplash photo-IDs — they will 404. Only use real, known URLs.\n- For buttons: action MUST use this exact nested format:\n \"action\": { \"event\": { \"name\": \"myAction\", \"context\": { \"key\": \"value\" } } }\n The \"event\" key holds an OBJECT with \"name\" (required) and \"context\" (optional).\n Do NOT use a flat format like {\"event\": \"name\"} — \"event\" must be an object.\n- For forms: check the component schema — if an input's \"value\" property\n supports path binding, use it for editable fields. The submit button's\n action context should reference the same paths to capture user input.\n\nUse the SAME surfaceId as the main surface. Match action names to button action event names.`;\n\n/** Description of the context entry that carries `GENERATIVE_UI_MARKDOWN_GUIDELINES`. */\nexport const GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION =\n \"Generative UI markdown guide: how to write UI surfaces inside ```a2ui code fences in a normal markdown reply.\";\n\n/**\n * Description of the context entry that carries the compact component schema\n * in the markdown transport.\n *\n * It must not equal `A2UI_SCHEMA_CONTEXT_DESCRIPTION` (the key that\n * `@ag-ui/a2ui-middleware` stamps for tool mode). The LangGraph and Strands\n * adapters find that exact string and move the entry into\n * `state[\"ag-ui\"][\"a2ui_schema\"]` for the `render_a2ui` tool, so it never\n * gets to the system prompt. The markdown transport has no tool, so the\n * schema must stay ordinary context that the model reads as App Context.\n */\nexport const GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION =\n \"Generative UI component schema: the components, props, events, slots, functions, and targets that ```a2ui code fences can use, and the surfaces that already exist.\";\n\n/** Which optional parts of A2UI a manifest uses. The guides leave out the rules for the others. */\nexport interface GenerativeUIGuideFeatures {\n /** A function is mounted: function calls and callRendererFunction. */\n functions: boolean;\n /** A component has an event prop. */\n events: boolean;\n /** A component has a \"multiple\" slot, which takes templates and @index. */\n templates: boolean;\n /** A component has a \"checks\" prop: validation rules on inputs. */\n checks: boolean;\n /**\n * The component names of the catalog. A guide line that names a standard\n * component missing from it is left out. Unset keeps every line.\n */\n components?: readonly string[];\n}\n\n/** Every optional rule group. Use it when the manifest is not known. */\nexport const ALL_GENERATIVE_UI_GUIDE_FEATURES: GenerativeUIGuideFeatures = {\n functions: true,\n events: true,\n templates: true,\n checks: true,\n};\n\n/**\n * The optional parts of A2UI that a manifest uses, so that a guide sends only\n * the rules that the model can apply.\n *\n * @param manifest - The components and the mounted functions of a run.\n * @returns Which optional rule groups the guides include.\n *\n * @example\n * ```ts\n * const guide = buildGenerativeUIMarkdownGuidelines(\n * generativeUIGuideFeatures(manifest),\n * );\n * ```\n */\nexport function generativeUIGuideFeatures(\n manifest: Pick<GenerativeUIManifest, \"components\" | \"functions\">,\n): GenerativeUIGuideFeatures {\n const components = Object.values(manifest.components);\n const hasChildList = (schema: unknown): boolean => {\n if (Array.isArray(schema)) return schema.some(hasChildList);\n if (typeof schema !== \"object\" || schema === null) return false;\n const node = schema as Record<string, unknown>;\n if (node.$ref === A2UI_CHILD_LIST_REF) return true;\n return Object.values(node).some(hasChildList);\n };\n return {\n components: Object.keys(manifest.components),\n // App functions only: the built-in ones are always there and have\n // their own rules.\n functions: Object.keys(manifest.functions).some(\n (name) => !isA2UIBasicFunction(name),\n ),\n events: components.some((c) => Object.keys(c.events ?? {}).length > 0),\n templates: components.some(\n (c) =>\n Object.values(c.slots ?? {}).includes(\"multiple\") ||\n hasChildList(c.props),\n ),\n checks: components.some((c) => {\n const properties = c.props.properties;\n return (\n typeof properties === \"object\" &&\n properties !== null &&\n Object.prototype.hasOwnProperty.call(properties, \"checks\")\n );\n }),\n };\n}\n\n/**\n * Whether a guide line names only standard components (`GUIDE_COMPONENTS`,\n * also in the plural) that the catalog has. With no catalog, every line fits.\n */\nfunction namesOnlyCatalogComponents(catalog: readonly string[] | undefined) {\n if (!catalog) return () => true;\n const has = new Set(catalog);\n return (line: string) =>\n (line.match(/\\b[A-Z][A-Za-z0-9]*\\b/g) ?? []).every((word) => {\n const name =\n !GUIDE_COMPONENTS.has(word) && word.endsWith(\"s\")\n ? word.slice(0, -1)\n : word;\n return !GUIDE_COMPONENTS.has(name) || has.has(name);\n });\n}\n\n/**\n * Builds the markdown-transport guideline. The model writes A2UI v1.0\n * operations inside ```a2ui fences between normal markdown prose. The rules\n * for functions, events, and templates are left out when the manifest has\n * none of them, so the guideline stays small.\n *\n * @param features - The optional rule groups to include. Defaults to all.\n * @param spec - The wording. Defaults to the prompts that ship.\n * @returns The guideline text, one rule per line.\n */\nexport function buildGenerativeUIMarkdownGuidelines(\n features: GenerativeUIGuideFeatures = ALL_GENERATIVE_UI_GUIDE_FEATURES,\n spec: GenerativeUIPromptSpec = defaultGenerativeUIPromptSpec(),\n) {\n const { intro, rules } = spec.markdown;\n const fits = namesOnlyCatalogComponents(features.components);\n const selected = selectPromptItems(\n rules,\n generativeUIPromptFeatures(features),\n ).filter(fits);\n const whenToShow = spec.markdown.whenToShow\n .split(\"\\n\")\n .filter(fits)\n .join(\"\\n\");\n const when = whenToShow ? `${whenToShow}\\n\\n` : \"\";\n return `${intro}\\n\\n${when}RULES\\n${selected.map((rule) => `- ${rule}`).join(\"\\n\")}\\n`;\n}\n\n/**\n * The markdown-transport guideline with every rule group. A run sends\n * `buildGenerativeUIMarkdownGuidelines` for its own manifest instead.\n */\nexport const GENERATIVE_UI_MARKDOWN_GUIDELINES =\n buildGenerativeUIMarkdownGu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I,QAAQ;AAC5B,SAAQ,UACL,KAAK,MAAM,yBAAyB,IAAI,EAAE,EAAE,OAAO,SAAS;EAC3D,MAAM,OACJ,CAACC,qCAAiB,IAAI,KAAK,IAAI,KAAK,SAAS,IAAI,GAC7C,KAAK,MAAM,GAAG,GAAG,GACjB;AACN,SAAO,CAACA,qCAAiB,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK;GACnD;;;;;;;;;;;;AAaN,SAAgB,oCACd,WAAsC,kCACtC,OAA+BC,mDAA+B,EAC9D;CACA,MAAM,EAAE,OAAO,UAAU,KAAK;CAC9B,MAAM,OAAO,2BAA2B,SAAS,WAAW;CAC5D,MAAM,WAAWC,sCACf,OACAC,+CAA2B,SAAS,CACrC,CAAC,OAAO,KAAK;CACd,MAAM,aAAa,KAAK,SAAS,WAC9B,MAAM,KAAK,CACX,OAAO,KAAK,CACZ,KAAK,KAAK;AAEb,QAAO,GAAG,MAAM,MADH,aAAa,GAAG,WAAW,QAAQ,GACrB,SAAS,SAAS,KAAK,SAAS,KAAK,OAAO,CAAC,KAAK,KAAK,CAAC;;;;;;AAOrF,MAAa,oCACX,qCAAqC"}
@@ -1,4 +1,5 @@
1
1
  import { GenerativeUIManifest } from "./generative-ui/types.cjs";
2
+ import { GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW, GENERATIVE_UI_WHEN_TO_SHOW, GenerativeUIPromptSpec } from "./generative-ui/prompt-spec.cjs";
2
3
 
3
4
  //#region src/a2ui-prompts.d.ts
4
5
  /**
@@ -41,6 +42,11 @@ interface GenerativeUIGuideFeatures {
41
42
  templates: boolean;
42
43
  /** A component has a "checks" prop: validation rules on inputs. */
43
44
  checks: boolean;
45
+ /**
46
+ * The component names of the catalog. A guide line that names a standard
47
+ * component missing from it is left out. Unset keeps every line.
48
+ */
49
+ components?: readonly string[];
44
50
  }
45
51
  /** Every optional rule group. Use it when the manifest is not known. */
46
52
  declare const ALL_GENERATIVE_UI_GUIDE_FEATURES: GenerativeUIGuideFeatures;
@@ -66,9 +72,10 @@ declare function generativeUIGuideFeatures(manifest: Pick<GenerativeUIManifest,
66
72
  * none of them, so the guideline stays small.
67
73
  *
68
74
  * @param features - The optional rule groups to include. Defaults to all.
75
+ * @param spec - The wording. Defaults to the prompts that ship.
69
76
  * @returns The guideline text, one rule per line.
70
77
  */
71
- declare function buildGenerativeUIMarkdownGuidelines(features?: GenerativeUIGuideFeatures): string;
78
+ declare function buildGenerativeUIMarkdownGuidelines(features?: GenerativeUIGuideFeatures, spec?: GenerativeUIPromptSpec): string;
72
79
  /**
73
80
  * The markdown-transport guideline with every rule group. A run sends
74
81
  * `buildGenerativeUIMarkdownGuidelines` for its own manifest instead.
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-prompts.d.cts","names":[],"sources":["../src/a2ui-prompts.ts"],"mappings":";;;;;AAeA;;;;;AAgFA;;;cAhFa,kCAAA;;AAkHb;;;cAlCa,8BAAA;AAoDb;AAAA,cAlBa,6CAAA;;;;;;;;;AA8Bb;;;cAhBa,iDAAA;;UAII,yBAAA;EAiCwB;EA/BvC,SAAA;EAgCe;EA9Bf,MAAA;EA+BC;EA7BD,SAAA;EA6B0B;EA3B1B,MAAA;AAAA;;cAIW,gCAAA,EAAkC,yBAAA;;;AAuG/C;;;;;AA0DA;;;;;;;iBA5IgB,yBAAA,CACd,QAAA,EAAU,IAAA,CAAK,oBAAA,gCACd,yBAAA;;;;;;;;;;iBAgFa,mCAAA,CACd,QAAA,GAAU,yBAAA;;;;;cAyDC,iCAAA"}
1
+ {"version":3,"file":"a2ui-prompts.d.cts","names":[],"sources":["../src/a2ui-prompts.ts"],"mappings":";;;;;AAyBA;;;;;AAgFA;;;;AAAA,cAhFa,kCAAA;AA0Gb;;;;AAAA,cA1Ba,8BAAA;AAwCb;AAAA,cAda,6CAAA;;;;AAkBb;;;;;;;;cAJa,iDAAA;;UAII,yBAAA;EAiBJ;EAfX,SAAA;;EAEA,MAAA;EAkBD;EAhBC,SAAA;EAgCuC;EA9BvC,MAAA;EA+Be;;;;EA1Bf,UAAA;AAAA;;cAIW,gCAAA,EAAkC,yBAAA;;;;AAmF/C;;;;;;;;;;AAsBA;iBApFgB,yBAAA,CACd,QAAA,EAAU,IAAA,CAAK,oBAAA,gCACd,yBAAA;;;;;;;;;;;iBA4Da,mCAAA,CACd,QAAA,GAAU,yBAAA,EACV,IAAA,GAAM,sBAAA;;;;;cAoBK,iCAAA"}
@@ -1,4 +1,5 @@
1
1
  import { GenerativeUIManifest } from "./generative-ui/types.mjs";
2
+ import { GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW, GENERATIVE_UI_WHEN_TO_SHOW, GenerativeUIPromptSpec } from "./generative-ui/prompt-spec.mjs";
2
3
 
3
4
  //#region src/a2ui-prompts.d.ts
4
5
  /**
@@ -41,6 +42,11 @@ interface GenerativeUIGuideFeatures {
41
42
  templates: boolean;
42
43
  /** A component has a "checks" prop: validation rules on inputs. */
43
44
  checks: boolean;
45
+ /**
46
+ * The component names of the catalog. A guide line that names a standard
47
+ * component missing from it is left out. Unset keeps every line.
48
+ */
49
+ components?: readonly string[];
44
50
  }
45
51
  /** Every optional rule group. Use it when the manifest is not known. */
46
52
  declare const ALL_GENERATIVE_UI_GUIDE_FEATURES: GenerativeUIGuideFeatures;
@@ -66,9 +72,10 @@ declare function generativeUIGuideFeatures(manifest: Pick<GenerativeUIManifest,
66
72
  * none of them, so the guideline stays small.
67
73
  *
68
74
  * @param features - The optional rule groups to include. Defaults to all.
75
+ * @param spec - The wording. Defaults to the prompts that ship.
69
76
  * @returns The guideline text, one rule per line.
70
77
  */
71
- declare function buildGenerativeUIMarkdownGuidelines(features?: GenerativeUIGuideFeatures): string;
78
+ declare function buildGenerativeUIMarkdownGuidelines(features?: GenerativeUIGuideFeatures, spec?: GenerativeUIPromptSpec): string;
72
79
  /**
73
80
  * The markdown-transport guideline with every rule group. A run sends
74
81
  * `buildGenerativeUIMarkdownGuidelines` for its own manifest instead.
@@ -1 +1 @@
1
- {"version":3,"file":"a2ui-prompts.d.mts","names":[],"sources":["../src/a2ui-prompts.ts"],"mappings":";;;;;AAeA;;;;;AAgFA;;;cAhFa,kCAAA;;AAkHb;;;cAlCa,8BAAA;AAoDb;AAAA,cAlBa,6CAAA;;;;;;;;;AA8Bb;;;cAhBa,iDAAA;;UAII,yBAAA;EAiCwB;EA/BvC,SAAA;EAgCe;EA9Bf,MAAA;EA+BC;EA7BD,SAAA;EA6B0B;EA3B1B,MAAA;AAAA;;cAIW,gCAAA,EAAkC,yBAAA;;;AAuG/C;;;;;AA0DA;;;;;;;iBA5IgB,yBAAA,CACd,QAAA,EAAU,IAAA,CAAK,oBAAA,gCACd,yBAAA;;;;;;;;;;iBAgFa,mCAAA,CACd,QAAA,GAAU,yBAAA;;;;;cAyDC,iCAAA"}
1
+ {"version":3,"file":"a2ui-prompts.d.mts","names":[],"sources":["../src/a2ui-prompts.ts"],"mappings":";;;;;AAyBA;;;;;AAgFA;;;;AAAA,cAhFa,kCAAA;AA0Gb;;;;AAAA,cA1Ba,8BAAA;AAwCb;AAAA,cAda,6CAAA;;;;AAkBb;;;;;;;;cAJa,iDAAA;;UAII,yBAAA;EAiBJ;EAfX,SAAA;;EAEA,MAAA;EAkBD;EAhBC,SAAA;EAgCuC;EA9BvC,MAAA;EA+Be;;;;EA1Bf,UAAA;AAAA;;cAIW,gCAAA,EAAkC,yBAAA;;;;AAmF/C;;;;;;;;;;AAsBA;iBApFgB,yBAAA,CACd,QAAA,EAAU,IAAA,CAAK,oBAAA,gCACd,yBAAA;;;;;;;;;;;iBA4Da,mCAAA,CACd,QAAA,GAAU,yBAAA,EACV,IAAA,GAAM,sBAAA;;;;;cAoBK,iCAAA"}