@copilotkit/shared 2.0.0-rc.0 → 2.0.0-rc.10

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 (220) hide show
  1. package/README.md +3 -14
  2. package/dist/a2ui-prompts.cjs +21 -62
  3. package/dist/a2ui-prompts.cjs.map +1 -1
  4. package/dist/a2ui-prompts.d.cts +8 -1
  5. package/dist/a2ui-prompts.d.cts.map +1 -1
  6. package/dist/a2ui-prompts.d.mts +8 -1
  7. package/dist/a2ui-prompts.d.mts.map +1 -1
  8. package/dist/a2ui-prompts.mjs +22 -62
  9. package/dist/a2ui-prompts.mjs.map +1 -1
  10. package/dist/generative-ui/basic-functions.cjs +1 -1
  11. package/dist/generative-ui/basic-functions.cjs.map +1 -1
  12. package/dist/generative-ui/basic-functions.mjs +1 -1
  13. package/dist/generative-ui/basic-functions.mjs.map +1 -1
  14. package/dist/generative-ui/compact-schema.cjs +187 -0
  15. package/dist/generative-ui/compact-schema.cjs.map +1 -0
  16. package/dist/generative-ui/compact-schema.d.cts +55 -0
  17. package/dist/generative-ui/compact-schema.d.cts.map +1 -0
  18. package/dist/generative-ui/compact-schema.d.mts +55 -0
  19. package/dist/generative-ui/compact-schema.d.mts.map +1 -0
  20. package/dist/generative-ui/compact-schema.mjs +185 -0
  21. package/dist/generative-ui/compact-schema.mjs.map +1 -0
  22. package/dist/generative-ui/prompt-spec.cjs +225 -0
  23. package/dist/generative-ui/prompt-spec.cjs.map +1 -0
  24. package/dist/generative-ui/prompt-spec.d.cts +94 -0
  25. package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
  26. package/dist/generative-ui/prompt-spec.d.mts +94 -0
  27. package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
  28. package/dist/generative-ui/prompt-spec.mjs +220 -0
  29. package/dist/generative-ui/prompt-spec.mjs.map +1 -0
  30. package/dist/generative-ui/prompt.cjs +10 -36
  31. package/dist/generative-ui/prompt.cjs.map +1 -1
  32. package/dist/generative-ui/prompt.d.cts +2 -1
  33. package/dist/generative-ui/prompt.d.cts.map +1 -1
  34. package/dist/generative-ui/prompt.d.mts +2 -1
  35. package/dist/generative-ui/prompt.d.mts.map +1 -1
  36. package/dist/generative-ui/prompt.mjs +12 -38
  37. package/dist/generative-ui/prompt.mjs.map +1 -1
  38. package/dist/generative-ui/schema-render.cjs +242 -0
  39. package/dist/generative-ui/schema-render.cjs.map +1 -0
  40. package/dist/generative-ui/schema-render.d.cts +44 -0
  41. package/dist/generative-ui/schema-render.d.cts.map +1 -0
  42. package/dist/generative-ui/schema-render.d.mts +44 -0
  43. package/dist/generative-ui/schema-render.d.mts.map +1 -0
  44. package/dist/generative-ui/schema-render.mjs +239 -0
  45. package/dist/generative-ui/schema-render.mjs.map +1 -0
  46. package/dist/index.cjs +17 -15
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +10 -9
  49. package/dist/index.d.cts.map +1 -1
  50. package/dist/index.d.mts +10 -9
  51. package/dist/index.d.mts.map +1 -1
  52. package/dist/index.mjs +9 -7
  53. package/dist/index.mjs.map +1 -1
  54. package/dist/index.umd.js +808 -438
  55. package/dist/index.umd.js.map +1 -1
  56. package/dist/package.cjs +1 -1
  57. package/dist/package.mjs +1 -1
  58. package/dist/standard-schema.cjs +20 -7
  59. package/dist/standard-schema.cjs.map +1 -1
  60. package/dist/standard-schema.d.cts +15 -16
  61. package/dist/standard-schema.d.cts.map +1 -1
  62. package/dist/standard-schema.d.mts +15 -16
  63. package/dist/standard-schema.d.mts.map +1 -1
  64. package/dist/standard-schema.mjs +20 -8
  65. package/dist/standard-schema.mjs.map +1 -1
  66. package/dist/telemetry/lambda-client.cjs.map +1 -1
  67. package/dist/telemetry/lambda-client.d.cts.map +1 -1
  68. package/dist/telemetry/lambda-client.d.mts.map +1 -1
  69. package/dist/telemetry/lambda-client.mjs.map +1 -1
  70. package/dist/telemetry/telemetry-disabled.cjs +3 -6
  71. package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
  72. package/dist/telemetry/telemetry-disabled.d.cts +0 -5
  73. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
  74. package/dist/telemetry/telemetry-disabled.d.mts +0 -5
  75. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
  76. package/dist/telemetry/telemetry-disabled.mjs +4 -6
  77. package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
  78. package/dist/types/message.d.cts +1 -18
  79. package/dist/types/message.d.cts.map +1 -1
  80. package/dist/types/message.d.mts +1 -18
  81. package/dist/types/message.d.mts.map +1 -1
  82. package/dist/utils/errors.cjs +4 -42
  83. package/dist/utils/errors.cjs.map +1 -1
  84. package/dist/utils/errors.d.cts +16 -34
  85. package/dist/utils/errors.d.cts.map +1 -1
  86. package/dist/utils/errors.d.mts +16 -34
  87. package/dist/utils/errors.d.mts.map +1 -1
  88. package/dist/utils/errors.mjs +5 -41
  89. package/dist/utils/errors.mjs.map +1 -1
  90. package/dist/utils/index.cjs +1 -2
  91. package/dist/utils/index.cjs.map +1 -1
  92. package/dist/utils/index.d.cts +4 -5
  93. package/dist/utils/index.d.cts.map +1 -1
  94. package/dist/utils/index.d.mts +4 -5
  95. package/dist/utils/index.d.mts.map +1 -1
  96. package/dist/utils/index.mjs +4 -5
  97. package/dist/utils/index.mjs.map +1 -1
  98. package/dist/utils/json-schema.cjs +0 -79
  99. package/dist/utils/json-schema.cjs.map +1 -1
  100. package/dist/utils/json-schema.d.cts +1 -4
  101. package/dist/utils/json-schema.d.cts.map +1 -1
  102. package/dist/utils/json-schema.d.mts +1 -4
  103. package/dist/utils/json-schema.d.mts.map +1 -1
  104. package/dist/utils/json-schema.mjs +1 -78
  105. package/dist/utils/json-schema.mjs.map +1 -1
  106. package/dist/utils/process-env.cjs +14 -0
  107. package/dist/utils/process-env.cjs.map +1 -0
  108. package/dist/utils/process-env.d.cts +10 -0
  109. package/dist/utils/process-env.d.cts.map +1 -0
  110. package/dist/utils/process-env.d.mts +10 -0
  111. package/dist/utils/process-env.d.mts.map +1 -0
  112. package/dist/utils/process-env.mjs +13 -0
  113. package/dist/utils/process-env.mjs.map +1 -0
  114. package/dist/utils/random-id.cjs +13 -26
  115. package/dist/utils/random-id.cjs.map +1 -1
  116. package/dist/utils/random-id.d.cts +6 -3
  117. package/dist/utils/random-id.d.cts.map +1 -1
  118. package/dist/utils/random-id.d.mts +6 -3
  119. package/dist/utils/random-id.d.mts.map +1 -1
  120. package/dist/utils/random-id.mjs +14 -25
  121. package/dist/utils/random-id.mjs.map +1 -1
  122. package/package.json +7 -31
  123. package/src/__tests__/a2ui-prompts.test.ts +42 -9
  124. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  125. package/src/__tests__/prompt-spec.test.ts +191 -0
  126. package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
  127. package/src/__tests__/schema-render.test.ts +245 -0
  128. package/src/__tests__/standard-schema.test.ts +61 -101
  129. package/src/a2ui-prompts.ts +47 -96
  130. package/src/generative-ui/basic-functions.ts +1 -1
  131. package/src/generative-ui/compact-schema.ts +277 -0
  132. package/src/generative-ui/index.ts +3 -0
  133. package/src/generative-ui/prompt-spec.ts +335 -0
  134. package/src/generative-ui/prompt.ts +25 -75
  135. package/src/generative-ui/schema-render.ts +374 -0
  136. package/src/index.ts +3 -16
  137. package/src/standard-schema.ts +24 -27
  138. package/src/telemetry/lambda-client.ts +3 -2
  139. package/src/telemetry/telemetry-disabled.ts +7 -12
  140. package/src/types/message.ts +1 -19
  141. package/src/utils/__tests__/errors.test.ts +44 -0
  142. package/src/utils/__tests__/json-schema.test.ts +3 -479
  143. package/src/utils/__tests__/process-env.test.ts +22 -0
  144. package/src/utils/__tests__/random-id.test.ts +37 -0
  145. package/src/utils/errors.ts +27 -85
  146. package/src/utils/index.ts +1 -2
  147. package/src/utils/json-schema.ts +1 -152
  148. package/src/utils/process-env.ts +14 -0
  149. package/src/utils/random-id.ts +17 -37
  150. package/tsdown.config.ts +2 -19
  151. package/dist/event-transforms/index.cjs +0 -15
  152. package/dist/event-transforms/index.d.cts +0 -4
  153. package/dist/event-transforms/index.d.mts +0 -4
  154. package/dist/event-transforms/index.mjs +0 -5
  155. package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
  156. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
  157. package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
  158. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
  159. package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
  160. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
  161. package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
  162. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
  163. package/dist/event-transforms/recorded-events.cjs +0 -59
  164. package/dist/event-transforms/recorded-events.cjs.map +0 -1
  165. package/dist/event-transforms/recorded-events.d.cts +0 -23
  166. package/dist/event-transforms/recorded-events.d.cts.map +0 -1
  167. package/dist/event-transforms/recorded-events.d.mts +0 -23
  168. package/dist/event-transforms/recorded-events.d.mts.map +0 -1
  169. package/dist/event-transforms/recorded-events.mjs +0 -58
  170. package/dist/event-transforms/recorded-events.mjs.map +0 -1
  171. package/dist/telemetry/events.d.cts +0 -72
  172. package/dist/telemetry/events.d.cts.map +0 -1
  173. package/dist/telemetry/events.d.mts +0 -72
  174. package/dist/telemetry/events.d.mts.map +0 -1
  175. package/dist/telemetry/index.cjs +0 -18
  176. package/dist/telemetry/index.d.cts +0 -5
  177. package/dist/telemetry/index.d.mts +0 -5
  178. package/dist/telemetry/index.mjs +0 -6
  179. package/dist/telemetry/telemetry-client.cjs +0 -165
  180. package/dist/telemetry/telemetry-client.cjs.map +0 -1
  181. package/dist/telemetry/telemetry-client.d.cts +0 -87
  182. package/dist/telemetry/telemetry-client.d.cts.map +0 -1
  183. package/dist/telemetry/telemetry-client.d.mts +0 -87
  184. package/dist/telemetry/telemetry-client.d.mts.map +0 -1
  185. package/dist/telemetry/telemetry-client.mjs +0 -164
  186. package/dist/telemetry/telemetry-client.mjs.map +0 -1
  187. package/dist/telemetry/utils.cjs +0 -14
  188. package/dist/telemetry/utils.cjs.map +0 -1
  189. package/dist/telemetry/utils.mjs +0 -13
  190. package/dist/telemetry/utils.mjs.map +0 -1
  191. package/dist/utils/conditions.cjs +0 -32
  192. package/dist/utils/conditions.cjs.map +0 -1
  193. package/dist/utils/conditions.d.cts +0 -31
  194. package/dist/utils/conditions.d.cts.map +0 -1
  195. package/dist/utils/conditions.d.mts +0 -31
  196. package/dist/utils/conditions.d.mts.map +0 -1
  197. package/dist/utils/conditions.mjs +0 -31
  198. package/dist/utils/conditions.mjs.map +0 -1
  199. package/dist/utils/console-styling.cjs +0 -91
  200. package/dist/utils/console-styling.cjs.map +0 -1
  201. package/dist/utils/console-styling.d.cts +0 -65
  202. package/dist/utils/console-styling.d.cts.map +0 -1
  203. package/dist/utils/console-styling.d.mts +0 -65
  204. package/dist/utils/console-styling.d.mts.map +0 -1
  205. package/dist/utils/console-styling.mjs +0 -85
  206. package/dist/utils/console-styling.mjs.map +0 -1
  207. package/src/__tests__/zod-regression.test.ts +0 -319
  208. package/src/event-transforms/index.ts +0 -5
  209. package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
  210. package/src/event-transforms/recorded-events.test.ts +0 -166
  211. package/src/event-transforms/recorded-events.ts +0 -74
  212. package/src/telemetry/events.ts +0 -68
  213. package/src/telemetry/index.ts +0 -9
  214. package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
  215. package/src/telemetry/telemetry-client.test.ts +0 -798
  216. package/src/telemetry/telemetry-client.ts +0 -328
  217. package/src/telemetry/utils.ts +0 -15
  218. package/src/utils/__tests__/conditions.test.ts +0 -161
  219. package/src/utils/conditions.ts +0 -116
  220. package/src/utils/console-styling.ts +0 -126
@@ -0,0 +1,185 @@
1
+ import { functionCallers } from "./basic-functions.mjs";
2
+ import { childRefKind } from "./child-refs.mjs";
3
+ import { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from "./types.mjs";
4
+
5
+ //#region src/generative-ui/compact-schema.ts
6
+ /** Objects nested deeper than this show as `object`. */
7
+ const MAX_OBJECT_DEPTH = 2;
8
+ /** A prop must appear verbatim in at least this many components to be hoisted. */
9
+ const COMMON_PROP_MIN_COMPONENTS = 8;
10
+ function isRecord(value) {
11
+ return typeof value === "object" && value !== null && !Array.isArray(value);
12
+ }
13
+ /** A JSON Schema of a list of schemas (`anyOf`, `oneOf`), else an empty list. */
14
+ function schemaList(value) {
15
+ return Array.isArray(value) ? value.filter(isRecord) : [];
16
+ }
17
+ /**
18
+ * Puts a top-level union in parentheses, so that `[]` applies to all of
19
+ * it. A union inside braces needs none.
20
+ */
21
+ function asArrayItem(type) {
22
+ let outside = type;
23
+ for (let inner = outside.replace(/\{[^{}]*\}/g, ""); inner !== outside;) {
24
+ outside = inner;
25
+ inner = outside.replace(/\{[^{}]*\}/g, "");
26
+ }
27
+ return outside.includes(" | ") ? `(${type})[]` : `${type}[]`;
28
+ }
29
+ /**
30
+ * A JSON Schema as a short TypeScript-like type, for example
31
+ * `{ label: string; size?: "sm" | "md" }`.
32
+ */
33
+ function compactType(schema, depth) {
34
+ const ref = childRefKind(schema);
35
+ if (ref === "single") return "componentId";
36
+ if (ref === "multiple") return "componentId[] | { componentId: string; path: string }";
37
+ if ("const" in schema) return JSON.stringify(schema.const);
38
+ if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
39
+ const variants = [...schemaList(schema.anyOf), ...schemaList(schema.oneOf)];
40
+ if (variants.length > 0) return variants.map((variant) => compactType(variant, depth)).join(" | ");
41
+ return (Array.isArray(schema.type) ? schema.type : [schema.type]).map((type) => {
42
+ switch (type) {
43
+ case "string":
44
+ case "boolean":
45
+ case "null": return type;
46
+ case "number":
47
+ case "integer": return "number";
48
+ case "array": return isRecord(schema.items) ? asArrayItem(compactType(schema.items, depth)) : "unknown[]";
49
+ case "object": return compactObject(schema, depth);
50
+ default: return "unknown";
51
+ }
52
+ }).join(" | ");
53
+ }
54
+ /** An object schema as `{ key: type; other?: type }`. */
55
+ function compactObject(schema, depth) {
56
+ const properties = isRecord(schema.properties) ? schema.properties : {};
57
+ const entries = Object.entries(properties);
58
+ if (entries.length === 0) return isRecord(schema.additionalProperties) ? `Record<string, ${compactType(schema.additionalProperties, depth + 1)}>` : "object";
59
+ if (depth >= MAX_OBJECT_DEPTH) return "object";
60
+ const required = Array.isArray(schema.required) ? schema.required : [];
61
+ return `{ ${entries.map(([key, value]) => {
62
+ const type = isRecord(value) ? compactType(value, depth + 1) : "unknown";
63
+ return `${key}${required.includes(key) ? "" : "?"}: ${type}`;
64
+ }).join("; ")} }`;
65
+ }
66
+ /** A schema as its type, with its description after `//`. */
67
+ function describedType(schema, depth) {
68
+ const type = compactType(schema, depth);
69
+ return typeof schema.description === "string" ? `${type} // ${schema.description}` : type;
70
+ }
71
+ /**
72
+ * The props of a component: `{ "label": "string", "size?": "..." }`. With
73
+ * `descriptions`, each type carries its description after `//`.
74
+ */
75
+ function compactProps(schema, descriptions = true) {
76
+ const properties = isRecord(schema.properties) ? schema.properties : {};
77
+ const required = Array.isArray(schema.required) ? schema.required : [];
78
+ const props = {};
79
+ for (const [key, value] of Object.entries(properties)) {
80
+ if (!isRecord(value)) continue;
81
+ const name = required.includes(key) ? key : `${key}?`;
82
+ props[name] = descriptions ? describedType(value, 1) : compactType(value, 1);
83
+ }
84
+ return props;
85
+ }
86
+ /**
87
+ * The prop set worth listing once. Candidates are (key, type) pairs that at
88
+ * least {@link COMMON_PROP_MIN_COMPONENTS} components carry verbatim. The
89
+ * candidate subset of each component is a possible common set, scored by
90
+ * the characters it saves (set size times the components that contain all
91
+ * of it). `undefined` when no set is shared by enough components.
92
+ */
93
+ function findCommonProps(propsList) {
94
+ const pairKey = (key, type) => `${key}\u0000${type}`;
95
+ const counts = /* @__PURE__ */ new Map();
96
+ for (const props of propsList) for (const [key, type] of Object.entries(props)) {
97
+ const id = pairKey(key, type);
98
+ counts.set(id, (counts.get(id) ?? 0) + 1);
99
+ }
100
+ let best;
101
+ let bestScore = 0;
102
+ const seen = /* @__PURE__ */ new Set();
103
+ for (const props of propsList) {
104
+ const subset = Object.entries(props).filter(([key, type]) => (counts.get(pairKey(key, type)) ?? 0) >= COMMON_PROP_MIN_COMPONENTS);
105
+ if (subset.length < 2) continue;
106
+ const signature = subset.map(([key, type]) => pairKey(key, type)).join("\n");
107
+ if (seen.has(signature)) continue;
108
+ seen.add(signature);
109
+ const members = propsList.filter((other) => subset.every(([key, type]) => other[key] === type)).length;
110
+ if (members < COMMON_PROP_MIN_COMPONENTS) continue;
111
+ const score = subset.reduce((total, [key, type]) => total + key.length + type.length, 0) * (members - 1);
112
+ if (score > bestScore) {
113
+ bestScore = score;
114
+ best = Object.fromEntries(subset);
115
+ }
116
+ }
117
+ return best;
118
+ }
119
+ /**
120
+ * The component schema of the markdown transport, from the per-run
121
+ * manifest. It is smaller than the manifest: each prop is one short type,
122
+ * and the props that many components share verbatim (the layout props of
123
+ * the containers) are listed once in `commonProps`; a component that takes
124
+ * them is flagged `includesCommonProps`.
125
+ * It has the catalog id, the targets with their descriptions and their
126
+ * component lists, the functions with their parameters, the components
127
+ * with their props, events and slots, and the surfaces of the thread. A surface lists the
128
+ * values that the user set and the operations that the client dropped.
129
+ *
130
+ * @param manifest - The manifest from `buildGenerativeUIManifest`.
131
+ * @param options - `propDescriptions` (default true) writes each prop's
132
+ * description; `commonProps` (default true) lists shared props once.
133
+ * @returns A JSON-ready object.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const value = JSON.stringify(
138
+ * buildCompactGenerativeUISchema(buildGenerativeUIManifest(runtime, threadId)),
139
+ * );
140
+ * ```
141
+ */
142
+ function buildCompactGenerativeUISchema(manifest, options = {}) {
143
+ const { propDescriptions = true, commonProps = true } = options;
144
+ const components = {};
145
+ for (const [name, component] of Object.entries(manifest.components)) {
146
+ const events = Object.entries(component.events ?? {}).map(([event, definition]) => [event, definition.description ?? compactType(definition.parameters, 0)]);
147
+ components[name] = {
148
+ ...component.description ? { description: component.description } : {},
149
+ props: compactProps(component.props, propDescriptions),
150
+ ...events.length > 0 ? { events: Object.fromEntries(events) } : {},
151
+ ...component.slots ? { slots: component.slots } : {}
152
+ };
153
+ }
154
+ const common = commonProps ? findCommonProps(Object.values(components).map((component) => component.props)) : void 0;
155
+ if (common) {
156
+ const commonKeys = Object.keys(common);
157
+ for (const component of Object.values(components)) {
158
+ if (!commonKeys.every((key) => component.props[key] === common[key])) continue;
159
+ component.includesCommonProps = true;
160
+ component.props = Object.fromEntries(Object.entries(component.props).filter(([key]) => !(key in common)));
161
+ }
162
+ }
163
+ const functions = Object.fromEntries(Object.entries(manifest.functions).map(([name, fn]) => {
164
+ const signature = fn.parameters.description;
165
+ const hasSignature = typeof signature === "string" && signature.startsWith("{") && Object.keys(fn.parameters).length === 2;
166
+ const callers = functionCallers(fn);
167
+ return [name, {
168
+ ...fn.description ? { description: fn.description } : {},
169
+ parameters: hasSignature ? signature : compactType(fn.parameters, 0),
170
+ ...callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS ? { callers: callers.renderer ? "UI or agent" : "agent only" } : {}
171
+ }];
172
+ }));
173
+ return {
174
+ catalogId: manifest.catalogId,
175
+ targets: manifest.targets,
176
+ functions,
177
+ ...common ? { commonProps: common } : {},
178
+ components,
179
+ surfaces: manifest.surfaces
180
+ };
181
+ }
182
+
183
+ //#endregion
184
+ export { buildCompactGenerativeUISchema, compactProps, compactType };
185
+ //# sourceMappingURL=compact-schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact-schema.mjs","names":[],"sources":["../../src/generative-ui/compact-schema.ts"],"sourcesContent":["import { childRefKind } from \"./child-refs\";\nimport { functionCallers } from \"./basic-functions\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type { GenerativeUIJSONSchema, GenerativeUIManifest } from \"./types\";\n\n/** Objects nested deeper than this show as `object`. */\nconst MAX_OBJECT_DEPTH = 2;\n\n/** A prop must appear verbatim in at least this many components to be hoisted. */\nconst COMMON_PROP_MIN_COMPONENTS = 8;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** A JSON Schema of a list of schemas (`anyOf`, `oneOf`), else an empty list. */\nfunction schemaList(value: unknown) {\n return Array.isArray(value) ? value.filter(isRecord) : [];\n}\n\n/**\n * Puts a top-level union in parentheses, so that `[]` applies to all of\n * it. A union inside braces needs none.\n */\nfunction asArrayItem(type: string) {\n let outside = type;\n for (let inner = outside.replace(/\\{[^{}]*\\}/g, \"\"); inner !== outside; ) {\n outside = inner;\n inner = outside.replace(/\\{[^{}]*\\}/g, \"\");\n }\n return outside.includes(\" | \") ? `(${type})[]` : `${type}[]`;\n}\n\n/**\n * A JSON Schema as a short TypeScript-like type, for example\n * `{ label: string; size?: \"sm\" | \"md\" }`.\n */\nexport function compactType(\n schema: GenerativeUIJSONSchema,\n depth: number,\n): string {\n const ref = childRefKind(schema);\n if (ref === \"single\") return \"componentId\";\n if (ref === \"multiple\")\n return \"componentId[] | { componentId: string; path: string }\";\n if (\"const\" in schema) return JSON.stringify(schema.const);\n if (Array.isArray(schema.enum)) {\n return schema.enum.map((value) => JSON.stringify(value)).join(\" | \");\n }\n const variants = [...schemaList(schema.anyOf), ...schemaList(schema.oneOf)];\n if (variants.length > 0) {\n return variants.map((variant) => compactType(variant, depth)).join(\" | \");\n }\n const types = Array.isArray(schema.type) ? schema.type : [schema.type];\n const summaries = types.map((type) => {\n switch (type) {\n case \"string\":\n case \"boolean\":\n case \"null\":\n return type;\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"array\":\n return isRecord(schema.items)\n ? asArrayItem(compactType(schema.items, depth))\n : \"unknown[]\";\n case \"object\":\n return compactObject(schema, depth);\n default:\n return \"unknown\";\n }\n });\n return summaries.join(\" | \");\n}\n\n/** An object schema as `{ key: type; other?: type }`. */\nfunction compactObject(schema: GenerativeUIJSONSchema, depth: number) {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const entries = Object.entries(properties);\n if (entries.length === 0) {\n return isRecord(schema.additionalProperties)\n ? `Record<string, ${compactType(schema.additionalProperties, depth + 1)}>`\n : \"object\";\n }\n if (depth >= MAX_OBJECT_DEPTH) return \"object\";\n const required = Array.isArray(schema.required) ? schema.required : [];\n const fields = entries.map(([key, value]) => {\n const type = isRecord(value) ? compactType(value, depth + 1) : \"unknown\";\n return `${key}${required.includes(key) ? \"\" : \"?\"}: ${type}`;\n });\n return `{ ${fields.join(\"; \")} }`;\n}\n\n/** A schema as its type, with its description after `//`. */\nfunction describedType(schema: GenerativeUIJSONSchema, depth: number) {\n const type = compactType(schema, depth);\n return typeof schema.description === \"string\"\n ? `${type} // ${schema.description}`\n : type;\n}\n\n/**\n * The props of a component: `{ \"label\": \"string\", \"size?\": \"...\" }`. With\n * `descriptions`, each type carries its description after `//`.\n */\nexport function compactProps(\n schema: GenerativeUIJSONSchema,\n descriptions = true,\n) {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const required = Array.isArray(schema.required) ? schema.required : [];\n const props: Record<string, string> = {};\n for (const [key, value] of Object.entries(properties)) {\n if (!isRecord(value)) continue;\n const name = required.includes(key) ? key : `${key}?`;\n props[name] = descriptions\n ? describedType(value, 1)\n : compactType(value, 1);\n }\n return props;\n}\n\n/**\n * The prop set worth listing once. Candidates are (key, type) pairs that at\n * least {@link COMMON_PROP_MIN_COMPONENTS} components carry verbatim. The\n * candidate subset of each component is a possible common set, scored by\n * the characters it saves (set size times the components that contain all\n * of it). `undefined` when no set is shared by enough components.\n */\nfunction findCommonProps(propsList: Array<Record<string, string>>) {\n const pairKey = (key: string, type: string) => `${key}\\u0000${type}`;\n const counts = new Map<string, number>();\n for (const props of propsList) {\n for (const [key, type] of Object.entries(props)) {\n const id = pairKey(key, type);\n counts.set(id, (counts.get(id) ?? 0) + 1);\n }\n }\n let best: Record<string, string> | undefined;\n let bestScore = 0;\n const seen = new Set<string>();\n for (const props of propsList) {\n const subset = Object.entries(props).filter(\n ([key, type]) =>\n (counts.get(pairKey(key, type)) ?? 0) >= COMMON_PROP_MIN_COMPONENTS,\n );\n if (subset.length < 2) continue;\n const signature = subset\n .map(([key, type]) => pairKey(key, type))\n .join(\"\\n\");\n if (seen.has(signature)) continue;\n seen.add(signature);\n const members = propsList.filter((other) =>\n subset.every(([key, type]) => other[key] === type),\n ).length;\n if (members < COMMON_PROP_MIN_COMPONENTS) continue;\n const size = subset.reduce(\n (total, [key, type]) => total + key.length + type.length,\n 0,\n );\n const score = size * (members - 1);\n if (score > bestScore) {\n bestScore = score;\n best = Object.fromEntries(subset);\n }\n }\n return best;\n}\n\n/** One component of the compact schema. */\ninterface CompactComponent {\n description?: string;\n /** True when the component also takes every prop in `commonProps`. */\n includesCommonProps?: true;\n props: Record<string, string>;\n events?: Record<string, string>;\n slots?: Record<string, \"single\" | \"multiple\">;\n}\n\n/**\n * The component schema of the markdown transport, from the per-run\n * manifest. It is smaller than the manifest: each prop is one short type,\n * and the props that many components share verbatim (the layout props of\n * the containers) are listed once in `commonProps`; a component that takes\n * them is flagged `includesCommonProps`.\n * It has the catalog id, the targets with their descriptions and their\n * component lists, the functions with their parameters, the components\n * with their props, events and slots, and the surfaces of the thread. A surface lists the\n * values that the user set and the operations that the client dropped.\n *\n * @param manifest - The manifest from `buildGenerativeUIManifest`.\n * @param options - `propDescriptions` (default true) writes each prop's\n * description; `commonProps` (default true) lists shared props once.\n * @returns A JSON-ready object.\n *\n * @example\n * ```ts\n * const value = JSON.stringify(\n * buildCompactGenerativeUISchema(buildGenerativeUIManifest(runtime, threadId)),\n * );\n * ```\n */\nexport function buildCompactGenerativeUISchema(\n manifest: Pick<\n GenerativeUIManifest,\n \"catalogId\" | \"components\" | \"functions\" | \"targets\" | \"surfaces\"\n >,\n options: { propDescriptions?: boolean; commonProps?: boolean } = {},\n) {\n const { propDescriptions = true, commonProps = true } = options;\n const components: Record<string, CompactComponent> = {};\n for (const [name, component] of Object.entries(manifest.components)) {\n const events = Object.entries(component.events ?? {}).map(\n ([event, definition]) => [\n event,\n definition.description ?? compactType(definition.parameters, 0),\n ],\n );\n components[name] = {\n ...(component.description ? { description: component.description } : {}),\n props: compactProps(component.props, propDescriptions),\n ...(events.length > 0 ? { events: Object.fromEntries(events) } : {}),\n ...(component.slots ? { slots: component.slots } : {}),\n };\n }\n const common = commonProps\n ? findCommonProps(\n Object.values(components).map((component) => component.props),\n )\n : undefined;\n if (common) {\n const commonKeys = Object.keys(common);\n for (const component of Object.values(components)) {\n const includesCommon = commonKeys.every(\n (key) => component.props[key] === common[key],\n );\n if (!includesCommon) continue;\n component.includesCommonProps = true;\n component.props = Object.fromEntries(\n Object.entries(component.props).filter(([key]) => !(key in common)),\n );\n }\n }\n // A built-in function carries its short signature in the description of\n // its parameters (see `builtInFunctionManifests`); an app function gets\n // its JSON Schema made short. A function is for the UI unless it says\n // that the agent may call it too, or only the agent.\n const functions = Object.fromEntries(\n Object.entries(manifest.functions).map(([name, fn]) => {\n const signature = fn.parameters.description;\n const hasSignature =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(fn.parameters).length === 2;\n const callers = functionCallers(fn);\n return [\n name,\n {\n ...(fn.description ? { description: fn.description } : {}),\n parameters: hasSignature ? signature : compactType(fn.parameters, 0),\n ...(callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? { callers: callers.renderer ? \"UI or agent\" : \"agent only\" }\n : {}),\n },\n ];\n }),\n );\n return {\n catalogId: manifest.catalogId,\n targets: manifest.targets,\n functions,\n ...(common ? { commonProps: common } : {}),\n components,\n surfaces: manifest.surfaces,\n };\n}\n"],"mappings":"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"}
@@ -0,0 +1,225 @@
1
+ const require_types = require('./types.cjs');
2
+
3
+ //#region src/generative-ui/prompt-spec.ts
4
+ /**
5
+ * When UI helps the user, for both transports: a light nudge to reach for UI
6
+ * where it conveys the answer better than prose, and to stay in prose
7
+ * otherwise.
8
+ */
9
+ 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.";
10
+ /**
11
+ * When and how to show UI in the markdown transport: the answer first, a
12
+ * map from tasks to components, real interactivity, honest data and
13
+ * restraint. Measured with tools/genui-eval against the earlier text.
14
+ */
15
+ const GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = "Answer first: lead with the result or the recommendation in a sentence or two, then show the UI that supports it.\n\nShow UI whenever it makes the answer easier to use, and do not wait for the user to ask for a chart, a calculator or a form. A markdown table or list is not enough when the user would want to change a value, see a shape or a trend, or pick between options. Reply in prose alone only for a greeting or thanks, a one-line fact, a definition, code, or a text the user asked you to write (an email, a message, an update).\n\nMatch the UI to the task:\n- A number that depends on inputs (a price, a loan or mortgage, savings, a conversion, a recipe for N people): a calculator, always. Bind a Slider, TextField or SegmentedControl to the data model and compute the results with calc, so they follow the input. calc has powers, roots and logs, so every input can be a control, also a rate or a term: a monthly payment is rate == 0 ? loan / (years * 12) : loan * (rate / 1200) / (1 - (1 + rate / 1200) ^ -(years * 12)).\n- Choosing between options that share attributes: a Table, or a Grid of EntityCards when each option has a photo, a price or a rating. Plans or offers to pick from: one card each, ending with a Button to choose it.\n- Items with a status, a category or a level: a Badge on each item.\n- Shares, patterns, trends, change over time: a Chart.\n- Places, routes, what is nearby: a Map with the places as markers, next to cards or a List with their details.\n- A sequence or a history: a timeline surface, a List of dated items with a Badge for each era, not a markdown list.\n- How something works, a process, a structure: a diagram drawn with Svg. Draw the real objects as shapes (a cylinder and its piston, a leaf, a server), with arrows for movement or flow and short labels. Labelled boxes of text are not a diagram.\n- A formula or an equation: Math. Solving a math problem: the steps in prose with Math, plus a Chart of the function and a Slider to try values of x.\n- A broad topic (\"tell me about X\"): an overview surface with the key facts, an Image, and a Table or Chart that compares the parts, ending with FollowUp suggestions for what to ask next.\n- Options to choose from (algorithms, products, plans): a Table, plus a SegmentedControl or Select that shows the best option for the user's situation.\n- Research or evidence: a Table of the studies, with a Citation for each source.\n- Things whose look matters (places, products, food): an Image, or the image of an EntityCard.\n- Several inputs, or an action with a side effect (sign-up, booking, contact, scheduling): a Form with fields, checks and a Button. A field with a fixed list of answers (a team size, a topic, a country) is a Select.\n- Practice and learning: a quiz with RadioGroup or ChoicePicker that gives feedback as soon as the user answers, or FlashcardFlip cards. Ask in one language and offer the answers in the other.\n- A plan to follow or tick off: CheckBox items with a progress count that updates as items are ticked.\n- Parallel views (the days of a trip, alternatives): Tabs.\n\nMake interactivity real:\n- Expose the few inputs that change the outcome, with sensible defaults from what the user said.\n- Bind every control to the data model and derive what depends on it with calc or formatString. Controls about the same scenario share the same paths.\n- Every Button does what its label says, and a Link takes \"href\".\n- Never pretend an action happened. For booking, sending or subscribing, show the form and let the user confirm, and say that nothing is sent until they do.\n\nKeep the data honest:\n- Use the facts, places, photos and numbers of the app context when it has them. Never invent prices, availability, ratings, sources or image URLs.\n- Label estimates and assumptions, keep units and currencies consistent, and cite the sources you rely on with Citation.\n\nDesign with restraint:\n- One clear surface beats several. Put the most important result first and make it stand out with a Title, or a Text with size \"lg\". Text sizes go from \"3xs\" to \"lg\"; there is no \"xl\" or \"2xl\".\n- Keep explanations in prose around the surface, not inside it. No decoration, and no surface that only holds text.\n\nBefore you reply, check: does the UI answer the actual question, does every control do something, are the numbers right?";
16
+ /** The prompts that ship, as a spec. A new object on each call. */
17
+ /**
18
+ * The standard components that the default markdown guide names. A guide
19
+ * line that names one the catalog lacks is left out of the prompt.
20
+ */
21
+ const GUIDE_COMPONENTS = new Set([
22
+ "Grid",
23
+ "Card",
24
+ "Tabs",
25
+ "Title",
26
+ "Text",
27
+ "Label",
28
+ "Badge",
29
+ "Math",
30
+ "Link",
31
+ "Button",
32
+ "Form",
33
+ "TextField",
34
+ "Select",
35
+ "CheckBox",
36
+ "RadioGroup",
37
+ "Slider",
38
+ "SegmentedControl",
39
+ "ChoicePicker",
40
+ "FlashcardFlip",
41
+ "Table",
42
+ "List",
43
+ "Chart",
44
+ "Map",
45
+ "Image",
46
+ "Svg",
47
+ "Citation",
48
+ "FollowUp",
49
+ "EntityCard"
50
+ ]);
51
+ function defaultGenerativeUIPromptSpec() {
52
+ return {
53
+ markdown: {
54
+ intro: "You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.",
55
+ whenToShow: GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW,
56
+ rules: [
57
+ "Write explanations as normal markdown prose outside the fences.",
58
+ "Open a fence with ```a2ui to show the surface in the chat, at the place of the fence.",
59
+ "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 limits its components, its surfaces can use only those components.",
60
+ "Inside a fence, write one JSON object per line and nothing else. No comments, no trailing commas, no pretty-printing.",
61
+ "Keep each operation whole on its line.",
62
+ "Give every operation \"version\":\"v1.0\".",
63
+ "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 ```",
64
+ "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.",
65
+ "Every surface renders from the component with id \"root\". Make every other component reachable from \"root\" through slots.",
66
+ "Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.",
67
+ "Use unique ids. Do not make cycles. A component cannot be its own child.",
68
+ "Write a component as one flat object: {\"id\":\"title\",\"component\":\"<Name>\",\"text\":\"Hello\"}.",
69
+ "Close each component with exactly one }, also when its last prop is a list: {\"id\":\"map\",\"component\":\"Map\",\"markers\":[{\"label\":\"A\",\"lat\":48.2,\"lng\":16.4}]}. A createSurface or updateComponents line ends with }]}} : the last component, the \"components\" list, the operation, the line.",
70
+ "A prop that holds a call closes with }} : its \"args\", then the call. The component closes with its own single } after its last prop. With a prop after the call: {\"id\":\"count\",\"component\":\"Text\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}},\"size\":\"lg\"}. With the call last: {\"id\":\"count\",\"component\":\"Text\",\"size\":\"lg\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}}}.",
71
+ "Deep props close every level they open, then the component closes with its own }. An event with a context: \"onSubmit\":{\"event\":{\"name\":\"send\",\"context\":{\"email\":{\"@path\":\"/email\"}}}}} ends with }}}}} : the path, \"context\", \"event\", the prop, the component. A Table: \"rows\":[[\"Mon\",\"9°C\"],[\"Tue\",\"7°C\"]]} ends with ]]} : the last row, \"rows\", the component, and nothing more. A list item with a call: \"items\":[{\"label\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} cups\"}}}]} ends with }}}]} : \"args\", the call, the item, the list, the component.",
72
+ "Put the component name in \"component\" (never \"type\"). Put props next to it, never inside a \"props\" object.",
73
+ "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. \"live\":\"polite\" goes only inside \"accessibility\" ({\"accessibility\":{\"live\":\"polite\"}}), only on text that changes by itself, never as a prop of the component.",
74
+ "Use only the components, props, events, and slots in the schema. A component marked +common also takes every common prop. A component with a prop that is not in its schema, or a value outside its enum, is dropped with everything inside it, so check each prop against the schema.",
75
+ "Give a prop a literal value, or bind it to the data model with {\"@path\":\"/x\"}. Never write {\"path\":\"/x\"} as a binding.",
76
+ "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 in the schema. Write a literal when the value never changes.",
77
+ "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.",
78
+ "${...} 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.",
79
+ "Inside ${...}, close every ( you open, and write no operators and no ?: : compute with calc. To round a computed number, round inside calc instead of wrapping it in formatNumber: ${calc(expression: 'round(servings * 0.5 * 10) / 10', servings: /servings)} cups. calc has ^ (power), sqrt, exp and ln.",
80
+ "To show one of two texts, let calc choose: \"text\":{\"@call\":\"calc\",\"args\":{\"expression\":\"billing == 'yearly' ? 'per year' : 'per month'\",\"billing\":{\"@path\":\"/billing\"}}}.",
81
+ "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.",
82
+ "Bind a writable prop to let the user edit it: \"value\":{\"@path\":\"/form/email\"}. The user's input goes to that path.",
83
+ "The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use \"yes\" and \"no\", not true and false.",
84
+ "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\".",
85
+ "Set \"value\":null to delete the key at \"path\".",
86
+ {
87
+ when: ["events"],
88
+ items: ["Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.", "Put the action of a Button in its \"onClick\": {\"event\":{...}} to send it back to you, or {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"...\"}}}. Never write \"event\" or \"functionCall\" as a prop of its own."]
89
+ },
90
+ {
91
+ when: ["events", "functions"],
92
+ items: ["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."]
93
+ },
94
+ {
95
+ when: ["events", "noFunctions"],
96
+ items: ["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."]
97
+ },
98
+ {
99
+ when: ["events"],
100
+ items: [
101
+ "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\".",
102
+ "To send input values with an event, bind them in the context: \"context\":{\"email\":{\"@path\":\"/form/email\"}}.",
103
+ "A button or other event prop without an event or functionCall does nothing."
104
+ ]
105
+ },
106
+ {
107
+ when: ["checks"],
108
+ items: ["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."]
109
+ },
110
+ "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\"}].",
111
+ {
112
+ when: ["templates"],
113
+ items: [
114
+ "To repeat a component for each item of a list, give a childList a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}.",
115
+ "Inside a template, paths are relative to the item (\"name\", not \"/name\").",
116
+ "Inside a template, {\"@call\":\"@index\"} gives the position of the item, from 0. To count from 1, write {\"@call\":\"@index\",\"args\":{\"offset\":1}}."
117
+ ]
118
+ },
119
+ "Updating a component replaces all of its props. Send every prop again.",
120
+ "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.",
121
+ "Use a new surfaceId for a different view. Never use a surfaceId again, also after the surface is deleted.",
122
+ {
123
+ when: ["agentCalls"],
124
+ items: [
125
+ "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.",
126
+ "Give every callRendererFunction a new functionCallId. Call only a function that the schema marks UI or agent, or agent only; a function with no mark is for the UI only. A function marked agent only is only for callRendererFunction: do not bind an event to it.",
127
+ "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.",
128
+ "Do not guess the result of a callRendererFunction. Wait for the developer message."
129
+ ]
130
+ },
131
+ "The schema lists the surfaces that already exist. \"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.",
132
+ "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.",
133
+ "Put in a fence only what markdown cannot show: charts, tables, maps, images, badges, inputs, buttons, cards with controls.",
134
+ "Use Card only for an interactive panel (controls, a form, a configurator). Put everything else in a plain layout component.",
135
+ "Never wrap the whole reply in a fence."
136
+ ]
137
+ },
138
+ tool: {
139
+ intro: `Call \`${require_types.GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).`,
140
+ whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,
141
+ operations: [
142
+ "{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
143
+ "{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
144
+ "{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
145
+ "{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
146
+ {
147
+ when: ["agentCalls"],
148
+ items: ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."]
149
+ }
150
+ ],
151
+ rules: [
152
+ "Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
153
+ "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.",
154
+ "Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
155
+ "Updating a component replaces all of its props, so resend every prop.",
156
+ "Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
157
+ {
158
+ when: ["events", "functions"],
159
+ items: ["Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below."]
160
+ },
161
+ {
162
+ when: ["events", "noFunctions"],
163
+ items: ["Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."]
164
+ },
165
+ "To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
166
+ "Never use a surfaceId again, also after deleteSurface.",
167
+ "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
168
+ "${...} 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\"}}}.",
169
+ "For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
170
+ {
171
+ when: ["checks"],
172
+ items: ["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 failed check shows the message under the input and disables a Button that has the same checks."]
173
+ },
174
+ {
175
+ when: ["templates"],
176
+ items: ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."]
177
+ },
178
+ {
179
+ when: ["agentCalls"],
180
+ items: ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."]
181
+ }
182
+ ]
183
+ },
184
+ schema: {
185
+ markdown: {
186
+ notation: "lines",
187
+ propDescriptions: true,
188
+ commonProps: true
189
+ },
190
+ tool: {
191
+ notation: "json-schema",
192
+ propDescriptions: true,
193
+ commonProps: false
194
+ }
195
+ },
196
+ descriptions: {}
197
+ };
198
+ }
199
+ /** The rules of `items` whose block conditions hold, in order. */
200
+ function selectPromptItems(items, features) {
201
+ return items.flatMap((item) => typeof item === "string" ? [item] : item.when.every((feature) => features[feature]) ? item.items : []);
202
+ }
203
+ /**
204
+ * The prompt features of a run, from the guide features of its manifest
205
+ * (`generativeUIGuideFeatures`).
206
+ */
207
+ function generativeUIPromptFeatures(guide) {
208
+ return {
209
+ functions: guide.functions,
210
+ noFunctions: !guide.functions,
211
+ events: guide.events,
212
+ templates: guide.templates,
213
+ checks: guide.checks,
214
+ agentCalls: guide.functions && require_types.GENERATIVE_UI_AGENT_FUNCTION_CALLS
215
+ };
216
+ }
217
+
218
+ //#endregion
219
+ exports.GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW = GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW;
220
+ exports.GENERATIVE_UI_WHEN_TO_SHOW = GENERATIVE_UI_WHEN_TO_SHOW;
221
+ exports.GUIDE_COMPONENTS = GUIDE_COMPONENTS;
222
+ exports.defaultGenerativeUIPromptSpec = defaultGenerativeUIPromptSpec;
223
+ exports.generativeUIPromptFeatures = generativeUIPromptFeatures;
224
+ exports.selectPromptItems = selectPromptItems;
225
+ //# sourceMappingURL=prompt-spec.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-spec.cjs","names":["GENERATIVE_UI_RENDER_TOOL","GENERATIVE_UI_AGENT_FUNCTION_CALLS"],"sources":["../../src/generative-ui/prompt-spec.ts"],"sourcesContent":["import {\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_RENDER_TOOL,\n} from \"./types\";\n\n/**\n * A condition of a prompt block. A block is in the prompt when every one of\n * its features holds for the manifest of the run.\n * - `functions` / `noFunctions`: the app mounts a function, or none.\n * - `events`, `templates`, `checks`: a component has an event prop, a\n * multiple slot, or a \"checks\" prop.\n * - `agentCalls`: the agent may call renderer functions (`functions` and\n * `GENERATIVE_UI_AGENT_FUNCTION_CALLS`).\n */\nexport type GenerativeUIPromptFeature =\n | \"functions\"\n | \"noFunctions\"\n | \"events\"\n | \"templates\"\n | \"checks\"\n | \"agentCalls\";\n\n/** One rule, or a block of rules that is in the prompt only when its features hold. */\nexport type GenerativeUIPromptItem =\n | string\n | { when: GenerativeUIPromptFeature[]; items: string[] };\n\n/** The instruction text of one transport. */\nexport interface GenerativeUIPromptSection {\n /** The first line. */\n intro: string;\n /** When UI helps. An empty string leaves the paragraph out. */\n whenToShow: string;\n /** The operations (tool transport only). */\n operations?: GenerativeUIPromptItem[];\n /** The rules, in order. */\n rules: GenerativeUIPromptItem[];\n}\n\n/** How the component schema is written. */\nexport interface GenerativeUISchemaSettings {\n /**\n * `compact` (short types, common props once), `json-schema` (the full\n * props schema), `ts-signature` (one line per component), or `lines`\n * (one line per prop, bare enums, common props once: the fewest tokens).\n */\n notation: \"compact\" | \"json-schema\" | \"ts-signature\" | \"lines\";\n /** Write the description of each prop. */\n propDescriptions: boolean;\n /** List the props that many components share once (`commonProps`). Compact and lines notations only. */\n commonProps: boolean;\n}\n\n/**\n * Everything in the generative UI prompts that is wording, not protocol: the\n * instruction text of both transports, how the component schema is\n * written, and replacement descriptions for components and props\n * (`\"DateTimeInput\"`, `\"DateTimeInput.timeStep\"`). The builders take a spec;\n * without one they use `defaultGenerativeUIPromptSpec()`, which renders the\n * prompts that ship. The descriptions are applied to the manifest by the\n * caller (`applyDescriptionOverrides`), because the schema is built from it.\n */\nexport interface GenerativeUIPromptSpec {\n markdown: GenerativeUIPromptSection;\n tool: GenerativeUIPromptSection;\n schema: {\n markdown: GenerativeUISchemaSettings;\n tool: GenerativeUISchemaSettings;\n };\n descriptions: Record<string, string>;\n}\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/**\n * When and how to show UI in the markdown transport: the answer first, a\n * map from tasks to components, real interactivity, honest data and\n * restraint. Measured with tools/genui-eval against the earlier text.\n */\nexport const GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW =\n 'Answer first: lead with the result or the recommendation in a sentence or two, then show the UI that supports it.\\n\\nShow UI whenever it makes the answer easier to use, and do not wait for the user to ask for a chart, a calculator or a form. A markdown table or list is not enough when the user would want to change a value, see a shape or a trend, or pick between options. Reply in prose alone only for a greeting or thanks, a one-line fact, a definition, code, or a text the user asked you to write (an email, a message, an update).\\n\\nMatch the UI to the task:\\n- A number that depends on inputs (a price, a loan or mortgage, savings, a conversion, a recipe for N people): a calculator, always. Bind a Slider, TextField or SegmentedControl to the data model and compute the results with calc, so they follow the input. calc has powers, roots and logs, so every input can be a control, also a rate or a term: a monthly payment is rate == 0 ? loan / (years * 12) : loan * (rate / 1200) / (1 - (1 + rate / 1200) ^ -(years * 12)).\\n- Choosing between options that share attributes: a Table, or a Grid of EntityCards when each option has a photo, a price or a rating. Plans or offers to pick from: one card each, ending with a Button to choose it.\\n- Items with a status, a category or a level: a Badge on each item.\\n- Shares, patterns, trends, change over time: a Chart.\\n- Places, routes, what is nearby: a Map with the places as markers, next to cards or a List with their details.\\n- A sequence or a history: a timeline surface, a List of dated items with a Badge for each era, not a markdown list.\\n- How something works, a process, a structure: a diagram drawn with Svg. Draw the real objects as shapes (a cylinder and its piston, a leaf, a server), with arrows for movement or flow and short labels. Labelled boxes of text are not a diagram.\\n- A formula or an equation: Math. Solving a math problem: the steps in prose with Math, plus a Chart of the function and a Slider to try values of x.\\n- A broad topic (\"tell me about X\"): an overview surface with the key facts, an Image, and a Table or Chart that compares the parts, ending with FollowUp suggestions for what to ask next.\\n- Options to choose from (algorithms, products, plans): a Table, plus a SegmentedControl or Select that shows the best option for the user\\'s situation.\\n- Research or evidence: a Table of the studies, with a Citation for each source.\\n- Things whose look matters (places, products, food): an Image, or the image of an EntityCard.\\n- Several inputs, or an action with a side effect (sign-up, booking, contact, scheduling): a Form with fields, checks and a Button. A field with a fixed list of answers (a team size, a topic, a country) is a Select.\\n- Practice and learning: a quiz with RadioGroup or ChoicePicker that gives feedback as soon as the user answers, or FlashcardFlip cards. Ask in one language and offer the answers in the other.\\n- A plan to follow or tick off: CheckBox items with a progress count that updates as items are ticked.\\n- Parallel views (the days of a trip, alternatives): Tabs.\\n\\nMake interactivity real:\\n- Expose the few inputs that change the outcome, with sensible defaults from what the user said.\\n- Bind every control to the data model and derive what depends on it with calc or formatString. Controls about the same scenario share the same paths.\\n- Every Button does what its label says, and a Link takes \"href\".\\n- Never pretend an action happened. For booking, sending or subscribing, show the form and let the user confirm, and say that nothing is sent until they do.\\n\\nKeep the data honest:\\n- Use the facts, places, photos and numbers of the app context when it has them. Never invent prices, availability, ratings, sources or image URLs.\\n- Label estimates and assumptions, keep units and currencies consistent, and cite the sources you rely on with Citation.\\n\\nDesign with restraint:\\n- One clear surface beats several. Put the most important result first and make it stand out with a Title, or a Text with size \"lg\". Text sizes go from \"3xs\" to \"lg\"; there is no \"xl\" or \"2xl\".\\n- Keep explanations in prose around the surface, not inside it. No decoration, and no surface that only holds text.\\n\\nBefore you reply, check: does the UI answer the actual question, does every control do something, are the numbers right?';\n\n/** The prompts that ship, as a spec. A new object on each call. */\n/**\n * The standard components that the default markdown guide names. A guide\n * line that names one the catalog lacks is left out of the prompt.\n */\nexport const GUIDE_COMPONENTS: ReadonlySet<string> = new Set([\n \"Grid\",\n \"Card\",\n \"Tabs\",\n \"Title\",\n \"Text\",\n \"Label\",\n \"Badge\",\n \"Math\",\n \"Link\",\n \"Button\",\n \"Form\",\n \"TextField\",\n \"Select\",\n \"CheckBox\",\n \"RadioGroup\",\n \"Slider\",\n \"SegmentedControl\",\n \"ChoicePicker\",\n \"FlashcardFlip\",\n \"Table\",\n \"List\",\n \"Chart\",\n \"Map\",\n \"Image\",\n \"Svg\",\n \"Citation\",\n \"FollowUp\",\n \"EntityCard\",\n]);\n\nexport function defaultGenerativeUIPromptSpec(): GenerativeUIPromptSpec {\n return {\n markdown: {\n intro:\n \"You can show interactive UI in your reply. Write A2UI operations inside a fenced code block tagged a2ui.\",\n whenToShow: GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW,\n 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 limits its 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 \"Send every component you reference in the same reply. If a surface gets long, make it smaller rather than leave components out.\",\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 'Close each component with exactly one }, also when its last prop is a list: {\"id\":\"map\",\"component\":\"Map\",\"markers\":[{\"label\":\"A\",\"lat\":48.2,\"lng\":16.4}]}. A createSurface or updateComponents line ends with }]}} : the last component, the \"components\" list, the operation, the line.',\n 'A prop that holds a call closes with }} : its \"args\", then the call. The component closes with its own single } after its last prop. With a prop after the call: {\"id\":\"count\",\"component\":\"Text\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}},\"size\":\"lg\"}. With the call last: {\"id\":\"count\",\"component\":\"Text\",\"size\":\"lg\",\"text\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} items\"}}}.',\n 'Deep props close every level they open, then the component closes with its own }. An event with a context: \"onSubmit\":{\"event\":{\"name\":\"send\",\"context\":{\"email\":{\"@path\":\"/email\"}}}}} ends with }}}}} : the path, \"context\", \"event\", the prop, the component. A Table: \"rows\":[[\"Mon\",\"9°C\"],[\"Tue\",\"7°C\"]]} ends with ]]} : the last row, \"rows\", the component, and nothing more. A list item with a call: \"items\":[{\"label\":{\"@call\":\"formatString\",\"args\":{\"value\":\"${/qty} cups\"}}}]} ends with }}}]} : \"args\", the call, the item, the list, the component.',\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. \"live\":\"polite\" goes only inside \"accessibility\" ({\"accessibility\":{\"live\":\"polite\"}}), only on text that changes by itself, never as a prop of the component.',\n \"Use only the components, props, events, and slots in the schema. A component marked +common also takes every common prop. A component with a prop that is not in its schema, or a value outside its enum, is dropped with everything inside it, so check each prop against the schema.\",\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 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 \"Inside ${...}, close every ( you open, and write no operators and no ?: : compute with calc. To round a computed number, round inside calc instead of wrapping it in formatNumber: ${calc(expression: 'round(servings * 0.5 * 10) / 10', servings: /servings)} cups. calc has ^ (power), sqrt, exp and ln.\",\n 'To show one of two texts, let calc choose: \"text\":{\"@call\":\"calc\",\"args\":{\"expression\":\"billing == \\'yearly\\' ? \\'per year\\' : \\'per month\\'\",\"billing\":{\"@path\":\"/billing\"}}}.',\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 'The value of a ChoicePicker is a list of strings, also for one choice. SegmentedControl, RadioGroup and Select take one string. Option values are always strings: for a yes/no choice use \"yes\" and \"no\", not true and false.',\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 when: [\"events\"],\n items: [\n 'Give an event prop an object: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} or {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}}. Never a flat {\"event\":\"<name>\"}.',\n 'Put the action of a Button in its \"onClick\": {\"event\":{...}} to send it back to you, or {\"functionCall\":{\"@call\":\"openUrl\",\"args\":{\"url\":\"...\"}}}. Never write \"event\" or \"functionCall\" as a prop of its own.',\n ],\n },\n {\n when: [\"events\", \"functions\"],\n items: [\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 ],\n },\n {\n when: [\"events\", \"noFunctions\"],\n items: [\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 ],\n },\n {\n when: [\"events\"],\n items: [\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 {\n when: [\"checks\"],\n items: [\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 '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 when: [\"templates\"],\n items: [\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 \"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 when: [\"agentCalls\"],\n items: [\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 that the schema marks UI or agent, or agent only; a function with no mark is for the UI only. A function marked 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 'The schema lists the surfaces that already exist. \"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 tool: {\n intro: `Call \\`${GENERATIVE_UI_RENDER_TOOL}\\` to show UI. Arguments: \\`target\\` first, then \\`operations\\` (A2UI v1.0 operations, applied in order).`,\n whenToShow: GENERATIVE_UI_WHEN_TO_SHOW,\n operations: [\n '{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.',\n '{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.',\n '{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".',\n '{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.',\n {\n when: [\"agentCalls\"],\n items: [\n '{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface.',\n ],\n },\n ],\n rules: [\n 'Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.',\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 'Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.',\n \"Updating a component replaces all of its props, so resend every prop.\",\n 'Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.',\n {\n when: [\"events\", \"functions\"],\n items: [\n 'Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below.',\n ],\n },\n {\n when: [\"events\", \"noFunctions\"],\n items: [\n 'Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".',\n ],\n },\n \"To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.\",\n \"Never use a surfaceId again, also after deleteSurface.\",\n 'A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.',\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\"}}}.',\n \"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.\",\n {\n when: [\"checks\"],\n items: [\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 failed check shows the message under the input and disables a Button that has the same checks.',\n ],\n },\n {\n when: [\"templates\"],\n items: [\n 'To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1.',\n ],\n },\n {\n when: [\"agentCalls\"],\n items: [\n \"Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.\",\n 'The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it.',\n ],\n },\n ],\n },\n schema: {\n markdown: {\n notation: \"lines\",\n propDescriptions: true,\n commonProps: true,\n },\n tool: {\n notation: \"json-schema\",\n propDescriptions: true,\n commonProps: false,\n },\n },\n descriptions: {},\n };\n}\n\n/** Which features hold for a run. */\nexport type GenerativeUIPromptFeatures = Record<\n GenerativeUIPromptFeature,\n boolean\n>;\n\n/** The rules of `items` whose block conditions hold, in order. */\nexport function selectPromptItems(\n items: readonly GenerativeUIPromptItem[],\n features: GenerativeUIPromptFeatures,\n): string[] {\n return items.flatMap((item) =>\n typeof item === \"string\"\n ? [item]\n : item.when.every((feature) => features[feature])\n ? item.items\n : [],\n );\n}\n\n/**\n * The prompt features of a run, from the guide features of its manifest\n * (`generativeUIGuideFeatures`).\n */\nexport function generativeUIPromptFeatures(guide: {\n functions: boolean;\n events: boolean;\n templates: boolean;\n checks: boolean;\n}): GenerativeUIPromptFeatures {\n return {\n functions: guide.functions,\n noFunctions: !guide.functions,\n events: guide.events,\n templates: guide.templates,\n checks: guide.checks,\n agentCalls: guide.functions && GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n };\n}\n"],"mappings":";;;;;;;;AA6EA,MAAa,6BACX;;;;;;AAOF,MAAa,sCACX;;;;;;AAOF,MAAa,mBAAwC,IAAI,IAAI;CAC3D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,gCAAwD;AACtE,QAAO;EACL,UAAU;GACR,OACE;GACF,YAAY;GACZ,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;KACE,MAAM,CAAC,SAAS;KAChB,OAAO,CACL,sNACA,qOACD;KACF;IACD;KACE,MAAM,CAAC,UAAU,YAAY;KAC7B,OAAO,CACL,0PACD;KACF;IACD;KACE,MAAM,CAAC,UAAU,cAAc;KAC/B,OAAO,CACL,0LACD;KACF;IACD;KACE,MAAM,CAAC,SAAS;KAChB,OAAO;MACL;MACA;MACA;MACD;KACF;IACD;KACE,MAAM,CAAC,SAAS;KAChB,OAAO,CACL,uXACD;KACF;IACD;IACA;KACE,MAAM,CAAC,YAAY;KACnB,OAAO;MACL;MACA;MACA;MACD;KACF;IACD;IACA;IACA;IACA;KACE,MAAM,CAAC,aAAa;KACpB,OAAO;MACL;MACA;MACA;MACA;MACD;KACF;IACD;IACA;IACA;IACA;IACA;IACD;GACF;EACD,MAAM;GACJ,OAAO,UAAUA,wCAA0B;GAC3C,YAAY;GACZ,YAAY;IACV;IACA;IACA;IACA;IACA;KACE,MAAM,CAAC,aAAa;KACpB,OAAO,CACL,gNACD;KACF;IACF;GACD,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;KACE,MAAM,CAAC,UAAU,YAAY;KAC7B,OAAO,CACL,qdACD;KACF;IACD;KACE,MAAM,CAAC,UAAU,cAAc;KAC/B,OAAO,CACL,sSACD;KACF;IACD;IACA;IACA;IACA;IACA;IACA;KACE,MAAM,CAAC,SAAS;KAChB,OAAO,CACL,wUACD;KACF;IACD;KACE,MAAM,CAAC,YAAY;KACnB,OAAO,CACL,0VACD;KACF;IACD;KACE,MAAM,CAAC,aAAa;KACpB,OAAO,CACL,6PACA,4TACD;KACF;IACF;GACF;EACD,QAAQ;GACN,UAAU;IACR,UAAU;IACV,kBAAkB;IAClB,aAAa;IACd;GACD,MAAM;IACJ,UAAU;IACV,kBAAkB;IAClB,aAAa;IACd;GACF;EACD,cAAc,EAAE;EACjB;;;AAUH,SAAgB,kBACd,OACA,UACU;AACV,QAAO,MAAM,SAAS,SACpB,OAAO,SAAS,WACZ,CAAC,KAAK,GACN,KAAK,KAAK,OAAO,YAAY,SAAS,SAAS,GAC7C,KAAK,QACL,EAAE,CACT;;;;;;AAOH,SAAgB,2BAA2B,OAKZ;AAC7B,QAAO;EACL,WAAW,MAAM;EACjB,aAAa,CAAC,MAAM;EACpB,QAAQ,MAAM;EACd,WAAW,MAAM;EACjB,QAAQ,MAAM;EACd,YAAY,MAAM,aAAaC;EAChC"}