@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.
- package/README.md +3 -14
- package/dist/a2ui-prompts.cjs +21 -62
- package/dist/a2ui-prompts.cjs.map +1 -1
- package/dist/a2ui-prompts.d.cts +8 -1
- package/dist/a2ui-prompts.d.cts.map +1 -1
- package/dist/a2ui-prompts.d.mts +8 -1
- package/dist/a2ui-prompts.d.mts.map +1 -1
- package/dist/a2ui-prompts.mjs +22 -62
- package/dist/a2ui-prompts.mjs.map +1 -1
- package/dist/generative-ui/basic-functions.cjs +1 -1
- package/dist/generative-ui/basic-functions.cjs.map +1 -1
- package/dist/generative-ui/basic-functions.mjs +1 -1
- package/dist/generative-ui/basic-functions.mjs.map +1 -1
- package/dist/generative-ui/compact-schema.cjs +187 -0
- package/dist/generative-ui/compact-schema.cjs.map +1 -0
- package/dist/generative-ui/compact-schema.d.cts +55 -0
- package/dist/generative-ui/compact-schema.d.cts.map +1 -0
- package/dist/generative-ui/compact-schema.d.mts +55 -0
- package/dist/generative-ui/compact-schema.d.mts.map +1 -0
- package/dist/generative-ui/compact-schema.mjs +185 -0
- package/dist/generative-ui/compact-schema.mjs.map +1 -0
- package/dist/generative-ui/prompt-spec.cjs +225 -0
- package/dist/generative-ui/prompt-spec.cjs.map +1 -0
- package/dist/generative-ui/prompt-spec.d.cts +94 -0
- package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
- package/dist/generative-ui/prompt-spec.d.mts +94 -0
- package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
- package/dist/generative-ui/prompt-spec.mjs +220 -0
- package/dist/generative-ui/prompt-spec.mjs.map +1 -0
- package/dist/generative-ui/prompt.cjs +10 -36
- package/dist/generative-ui/prompt.cjs.map +1 -1
- package/dist/generative-ui/prompt.d.cts +2 -1
- package/dist/generative-ui/prompt.d.cts.map +1 -1
- package/dist/generative-ui/prompt.d.mts +2 -1
- package/dist/generative-ui/prompt.d.mts.map +1 -1
- package/dist/generative-ui/prompt.mjs +12 -38
- package/dist/generative-ui/prompt.mjs.map +1 -1
- package/dist/generative-ui/schema-render.cjs +242 -0
- package/dist/generative-ui/schema-render.cjs.map +1 -0
- package/dist/generative-ui/schema-render.d.cts +44 -0
- package/dist/generative-ui/schema-render.d.cts.map +1 -0
- package/dist/generative-ui/schema-render.d.mts +44 -0
- package/dist/generative-ui/schema-render.d.mts.map +1 -0
- package/dist/generative-ui/schema-render.mjs +239 -0
- package/dist/generative-ui/schema-render.mjs.map +1 -0
- package/dist/index.cjs +17 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -7
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +808 -438
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/standard-schema.cjs +20 -7
- package/dist/standard-schema.cjs.map +1 -1
- package/dist/standard-schema.d.cts +15 -16
- package/dist/standard-schema.d.cts.map +1 -1
- package/dist/standard-schema.d.mts +15 -16
- package/dist/standard-schema.d.mts.map +1 -1
- package/dist/standard-schema.mjs +20 -8
- package/dist/standard-schema.mjs.map +1 -1
- package/dist/telemetry/lambda-client.cjs.map +1 -1
- package/dist/telemetry/lambda-client.d.cts.map +1 -1
- package/dist/telemetry/lambda-client.d.mts.map +1 -1
- package/dist/telemetry/lambda-client.mjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.cjs +3 -6
- package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.cts +0 -5
- package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
- package/dist/telemetry/telemetry-disabled.d.mts +0 -5
- package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
- package/dist/telemetry/telemetry-disabled.mjs +4 -6
- package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
- package/dist/types/message.d.cts +1 -18
- package/dist/types/message.d.cts.map +1 -1
- package/dist/types/message.d.mts +1 -18
- package/dist/types/message.d.mts.map +1 -1
- package/dist/utils/errors.cjs +4 -42
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.d.cts +16 -34
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.mts +16 -34
- package/dist/utils/errors.d.mts.map +1 -1
- package/dist/utils/errors.mjs +5 -41
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +1 -2
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -5
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +4 -5
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +4 -5
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/json-schema.cjs +0 -79
- package/dist/utils/json-schema.cjs.map +1 -1
- package/dist/utils/json-schema.d.cts +1 -4
- package/dist/utils/json-schema.d.cts.map +1 -1
- package/dist/utils/json-schema.d.mts +1 -4
- package/dist/utils/json-schema.d.mts.map +1 -1
- package/dist/utils/json-schema.mjs +1 -78
- package/dist/utils/json-schema.mjs.map +1 -1
- package/dist/utils/process-env.cjs +14 -0
- package/dist/utils/process-env.cjs.map +1 -0
- package/dist/utils/process-env.d.cts +10 -0
- package/dist/utils/process-env.d.cts.map +1 -0
- package/dist/utils/process-env.d.mts +10 -0
- package/dist/utils/process-env.d.mts.map +1 -0
- package/dist/utils/process-env.mjs +13 -0
- package/dist/utils/process-env.mjs.map +1 -0
- package/dist/utils/random-id.cjs +13 -26
- package/dist/utils/random-id.cjs.map +1 -1
- package/dist/utils/random-id.d.cts +6 -3
- package/dist/utils/random-id.d.cts.map +1 -1
- package/dist/utils/random-id.d.mts +6 -3
- package/dist/utils/random-id.d.mts.map +1 -1
- package/dist/utils/random-id.mjs +14 -25
- package/dist/utils/random-id.mjs.map +1 -1
- package/package.json +7 -31
- package/src/__tests__/a2ui-prompts.test.ts +42 -9
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/__tests__/standard-schema.test.ts +61 -101
- package/src/a2ui-prompts.ts +47 -96
- package/src/generative-ui/basic-functions.ts +1 -1
- package/src/generative-ui/compact-schema.ts +277 -0
- package/src/generative-ui/index.ts +3 -0
- package/src/generative-ui/prompt-spec.ts +335 -0
- package/src/generative-ui/prompt.ts +25 -75
- package/src/generative-ui/schema-render.ts +374 -0
- package/src/index.ts +3 -16
- package/src/standard-schema.ts +24 -27
- package/src/telemetry/lambda-client.ts +3 -2
- package/src/telemetry/telemetry-disabled.ts +7 -12
- package/src/types/message.ts +1 -19
- package/src/utils/__tests__/errors.test.ts +44 -0
- package/src/utils/__tests__/json-schema.test.ts +3 -479
- package/src/utils/__tests__/process-env.test.ts +22 -0
- package/src/utils/__tests__/random-id.test.ts +37 -0
- package/src/utils/errors.ts +27 -85
- package/src/utils/index.ts +1 -2
- package/src/utils/json-schema.ts +1 -152
- package/src/utils/process-env.ts +14 -0
- package/src/utils/random-id.ts +17 -37
- package/tsdown.config.ts +2 -19
- package/dist/event-transforms/index.cjs +0 -15
- package/dist/event-transforms/index.d.cts +0 -4
- package/dist/event-transforms/index.d.mts +0 -4
- package/dist/event-transforms/index.mjs +0 -5
- package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
- package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
- package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
- package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
- package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
- package/dist/event-transforms/recorded-events.cjs +0 -59
- package/dist/event-transforms/recorded-events.cjs.map +0 -1
- package/dist/event-transforms/recorded-events.d.cts +0 -23
- package/dist/event-transforms/recorded-events.d.cts.map +0 -1
- package/dist/event-transforms/recorded-events.d.mts +0 -23
- package/dist/event-transforms/recorded-events.d.mts.map +0 -1
- package/dist/event-transforms/recorded-events.mjs +0 -58
- package/dist/event-transforms/recorded-events.mjs.map +0 -1
- package/dist/telemetry/events.d.cts +0 -72
- package/dist/telemetry/events.d.cts.map +0 -1
- package/dist/telemetry/events.d.mts +0 -72
- package/dist/telemetry/events.d.mts.map +0 -1
- package/dist/telemetry/index.cjs +0 -18
- package/dist/telemetry/index.d.cts +0 -5
- package/dist/telemetry/index.d.mts +0 -5
- package/dist/telemetry/index.mjs +0 -6
- package/dist/telemetry/telemetry-client.cjs +0 -165
- package/dist/telemetry/telemetry-client.cjs.map +0 -1
- package/dist/telemetry/telemetry-client.d.cts +0 -87
- package/dist/telemetry/telemetry-client.d.cts.map +0 -1
- package/dist/telemetry/telemetry-client.d.mts +0 -87
- package/dist/telemetry/telemetry-client.d.mts.map +0 -1
- package/dist/telemetry/telemetry-client.mjs +0 -164
- package/dist/telemetry/telemetry-client.mjs.map +0 -1
- package/dist/telemetry/utils.cjs +0 -14
- package/dist/telemetry/utils.cjs.map +0 -1
- package/dist/telemetry/utils.mjs +0 -13
- package/dist/telemetry/utils.mjs.map +0 -1
- package/dist/utils/conditions.cjs +0 -32
- package/dist/utils/conditions.cjs.map +0 -1
- package/dist/utils/conditions.d.cts +0 -31
- package/dist/utils/conditions.d.cts.map +0 -1
- package/dist/utils/conditions.d.mts +0 -31
- package/dist/utils/conditions.d.mts.map +0 -1
- package/dist/utils/conditions.mjs +0 -31
- package/dist/utils/conditions.mjs.map +0 -1
- package/dist/utils/console-styling.cjs +0 -91
- package/dist/utils/console-styling.cjs.map +0 -1
- package/dist/utils/console-styling.d.cts +0 -65
- package/dist/utils/console-styling.d.cts.map +0 -1
- package/dist/utils/console-styling.d.mts +0 -65
- package/dist/utils/console-styling.d.mts.map +0 -1
- package/dist/utils/console-styling.mjs +0 -85
- package/dist/utils/console-styling.mjs.map +0 -1
- package/src/__tests__/zod-regression.test.ts +0 -319
- package/src/event-transforms/index.ts +0 -5
- package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
- package/src/event-transforms/recorded-events.test.ts +0 -166
- package/src/event-transforms/recorded-events.ts +0 -74
- package/src/telemetry/events.ts +0 -68
- package/src/telemetry/index.ts +0 -9
- package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
- package/src/telemetry/telemetry-client.test.ts +0 -798
- package/src/telemetry/telemetry-client.ts +0 -328
- package/src/telemetry/utils.ts +0 -15
- package/src/utils/__tests__/conditions.test.ts +0 -161
- package/src/utils/conditions.ts +0 -116
- 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
|
-
|
|
210
|
-
`
|
|
211
|
-
|
|
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.
|
package/dist/a2ui-prompts.cjs
CHANGED
|
@@ -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
|
|
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
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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 {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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 buildGenerativeUIMarkdownGuidelines();\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,MAAa,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFlD,MAAa,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;AA0B9C,MAAa,gDACX;;;;;;;;;;;;AAaF,MAAa,oDACX;;AAoBF,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;EACL,YAAY,OAAO,KAAK,SAAS,WAAW;EAG5C,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;;;;;;AAOH,SAAS,2BAA2B,SAAwC;AAC1E,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,MAAM,IAAI,IAAI,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"}
|
package/dist/a2ui-prompts.d.cts
CHANGED
|
@@ -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":";;;;;
|
|
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"}
|
package/dist/a2ui-prompts.d.mts
CHANGED
|
@@ -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":";;;;;
|
|
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"}
|
package/dist/a2ui-prompts.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isA2UIBasicFunction } from "./generative-ui/basic-functions.mjs";
|
|
2
2
|
import { A2UI_CHILD_LIST_REF } from "./generative-ui/child-refs.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { GENERATIVE_UI_MARKDOWN_WHEN_TO_SHOW, GENERATIVE_UI_WHEN_TO_SHOW, GUIDE_COMPONENTS, defaultGenerativeUIPromptSpec, generativeUIPromptFeatures, selectPromptItems } from "./generative-ui/prompt-spec.mjs";
|
|
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) => !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
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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 = !GUIDE_COMPONENTS.has(word) && word.endsWith("s") ? word.slice(0, -1) : word;
|
|
183
|
+
return !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 {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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 && 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 = defaultGenerativeUIPromptSpec()) {
|
|
197
|
+
const { intro, rules } = spec.markdown;
|
|
198
|
+
const fits = namesOnlyCatalogComponents(features.components);
|
|
199
|
+
const selected = selectPromptItems(rules, 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
|
|
@@ -247,5 +207,5 @@ ${rules.map((rule) => `- ${rule}`).join("\n")}
|
|
|
247
207
|
const GENERATIVE_UI_MARKDOWN_GUIDELINES = buildGenerativeUIMarkdownGuidelines();
|
|
248
208
|
|
|
249
209
|
//#endregion
|
|
250
|
-
export { A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, ALL_GENERATIVE_UI_GUIDE_FEATURES, GENERATIVE_UI_MARKDOWN_GUIDELINES, GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION, GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION,
|
|
210
|
+
export { A2UI_DEFAULT_DESIGN_GUIDELINES, A2UI_DEFAULT_GENERATION_GUIDELINES, ALL_GENERATIVE_UI_GUIDE_FEATURES, GENERATIVE_UI_MARKDOWN_GUIDELINES, GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION, GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION, buildGenerativeUIMarkdownGuidelines, generativeUIGuideFeatures };
|
|
251
211
|
//# sourceMappingURL=a2ui-prompts.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-prompts.mjs","names":[],"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,SAAS,oBAAqB,QAAO;AAC9C,SAAO,OAAO,OAAO,KAAK,CAAC,KAAK,aAAa;;AAE/C,QAAO;EAGL,WAAW,OAAO,KAAK,SAAS,UAAU,CAAC,MACxC,SAAS,CAAC,oBAAoB,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,aAAa,mCACf,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.mjs","names":[],"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 buildGenerativeUIMarkdownGuidelines();\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,MAAa,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFlD,MAAa,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;AA0B9C,MAAa,gDACX;;;;;;;;;;;;AAaF,MAAa,oDACX;;AAoBF,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,SAAS,oBAAqB,QAAO;AAC9C,SAAO,OAAO,OAAO,KAAK,CAAC,KAAK,aAAa;;AAE/C,QAAO;EACL,YAAY,OAAO,KAAK,SAAS,WAAW;EAG5C,WAAW,OAAO,KAAK,SAAS,UAAU,CAAC,MACxC,SAAS,CAAC,oBAAoB,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;;;;;;AAOH,SAAS,2BAA2B,SAAwC;AAC1E,KAAI,CAAC,QAAS,cAAa;CAC3B,MAAM,MAAM,IAAI,IAAI,QAAQ;AAC5B,SAAQ,UACL,KAAK,MAAM,yBAAyB,IAAI,EAAE,EAAE,OAAO,SAAS;EAC3D,MAAM,OACJ,CAAC,iBAAiB,IAAI,KAAK,IAAI,KAAK,SAAS,IAAI,GAC7C,KAAK,MAAM,GAAG,GAAG,GACjB;AACN,SAAO,CAAC,iBAAiB,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK;GACnD;;;;;;;;;;;;AAaN,SAAgB,oCACd,WAAsC,kCACtC,OAA+B,+BAA+B,EAC9D;CACA,MAAM,EAAE,OAAO,UAAU,KAAK;CAC9B,MAAM,OAAO,2BAA2B,SAAS,WAAW;CAC5D,MAAM,WAAW,kBACf,OACA,2BAA2B,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"}
|
|
@@ -123,7 +123,7 @@ const A2UI_BASIC_FUNCTIONS = rendererOnly({
|
|
|
123
123
|
*/
|
|
124
124
|
const COPILOTKIT_FUNCTIONS = rendererOnly({
|
|
125
125
|
calc: {
|
|
126
|
-
description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), comparisons, && || !, cond ? a : b, min max round floor ceil abs, 'text' + name",
|
|
126
|
+
description: "The value of an arithmetic expression over the other args, by name: + - * / % ( ), x ^ y (power), comparisons, && || !, cond ? a : b, min max round floor ceil abs pow sqrt exp ln log10, the constants pi and e, 'text' + name",
|
|
127
127
|
parameters: "{ expression: string; [name: string]: number | string | boolean }",
|
|
128
128
|
returnType: "any",
|
|
129
129
|
extension: true
|