@copilotkit/shared 1.83.0 → 1.84.1
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/dist/a2ui-catalog-schema.cjs +264 -0
- package/dist/a2ui-catalog-schema.cjs.map +1 -0
- package/dist/a2ui-catalog-schema.d.cts +112 -0
- package/dist/a2ui-catalog-schema.d.cts.map +1 -0
- package/dist/a2ui-catalog-schema.d.mts +112 -0
- package/dist/a2ui-catalog-schema.d.mts.map +1 -0
- package/dist/a2ui-catalog-schema.mjs +259 -0
- package/dist/a2ui-catalog-schema.mjs.map +1 -0
- package/dist/a2ui-envelope.cjs +2 -2
- package/dist/a2ui-envelope.cjs.map +1 -1
- package/dist/a2ui-envelope.d.cts +1 -1
- package/dist/a2ui-envelope.d.cts.map +1 -1
- package/dist/a2ui-envelope.d.mts +1 -1
- package/dist/a2ui-envelope.d.mts.map +1 -1
- package/dist/a2ui-envelope.mjs +2 -2
- package/dist/a2ui-envelope.mjs.map +1 -1
- 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/generative-ui/types.cjs +2 -2
- package/dist/generative-ui/types.cjs.map +1 -1
- package/dist/generative-ui/types.d.cts +7 -7
- package/dist/generative-ui/types.d.cts.map +1 -1
- package/dist/generative-ui/types.d.mts +7 -7
- package/dist/generative-ui/types.d.mts.map +1 -1
- package/dist/generative-ui/types.mjs +2 -2
- package/dist/generative-ui/types.mjs.map +1 -1
- package/dist/index.cjs +20 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +5 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1023 -169
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
- package/src/__tests__/a2ui-catalog-schema.test.ts +403 -0
- package/src/__tests__/a2ui-envelope.test.ts +18 -13
- package/src/__tests__/a2ui-prompts.test.ts +47 -14
- package/src/__tests__/fixtures/prompt-goldens.json +354 -0
- package/src/__tests__/prompt-spec.test.ts +191 -0
- package/src/__tests__/schema-render.test.ts +245 -0
- package/src/a2ui-catalog-schema.ts +404 -0
- package/src/a2ui-envelope.ts +5 -5
- package/src/a2ui-prompts.ts +47 -96
- package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
- package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
- 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/generative-ui/types.ts +10 -7
- package/src/index.ts +13 -0
- package/src/utils/__tests__/conditions.test.ts +153 -43
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { ignoreOverride, zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
+
|
|
3
|
+
//#region src/a2ui-catalog-schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Context description used to identify the A2UI component schema in
|
|
6
|
+
* RunAgentInput.context. Must match the constant in @ag-ui/a2ui-middleware so
|
|
7
|
+
* the middleware can overwrite a frontend-provided schema with a server-side one.
|
|
8
|
+
*/
|
|
9
|
+
const A2UI_SCHEMA_CONTEXT_DESCRIPTION = "A2UI Component Schema — available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.";
|
|
10
|
+
/** Id of the A2UI v0.9 basic catalog. */
|
|
11
|
+
const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json";
|
|
12
|
+
/**
|
|
13
|
+
* Serialize a catalog's Zod schemas in the A2UI v0.9 inline catalog format.
|
|
14
|
+
*
|
|
15
|
+
* Each component composes `ComponentCommon` with its own properties, matching
|
|
16
|
+
* the flat wire format the agent must produce:
|
|
17
|
+
*
|
|
18
|
+
* { "Column": { "allOf": [
|
|
19
|
+
* { "$ref": "common_types.json#/$defs/ComponentCommon" },
|
|
20
|
+
* { "properties": { "component": {"const":"Column"}, "gap": ..., "children": ... },
|
|
21
|
+
* "required": ["component"] }
|
|
22
|
+
* ]}}
|
|
23
|
+
*
|
|
24
|
+
* This follows `getClientCapabilities` in `@a2ui/web_core` with these
|
|
25
|
+
* deliberate differences:
|
|
26
|
+
*
|
|
27
|
+
* - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which
|
|
28
|
+
* would dangle once properties move under `allOf[1]`.
|
|
29
|
+
* - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but
|
|
30
|
+
* the shape it replaced is kept once under
|
|
31
|
+
* `"common_types.json": { "$defs": { <Name>: ... } }`. Every
|
|
32
|
+
* `common_types.json#/$defs/<Name>` ref therefore resolves within the
|
|
33
|
+
* payload, both for agents that only see it as prompt text and for SDKs
|
|
34
|
+
* (such as Google's A2UI SDK used by ADK) that read the `$ref`. Each type is
|
|
35
|
+
* stated once rather than at every use site, which keeps the payload small.
|
|
36
|
+
* A use whose shape differs from the stored one keeps its shape inline next
|
|
37
|
+
* to the `$ref`, so the agent never sees a looser type than the client
|
|
38
|
+
* accepts.
|
|
39
|
+
* - A `REF:` marker on a schema's root only sets its description; replacing
|
|
40
|
+
* the root would drop every property.
|
|
41
|
+
* - A component's root `.describe()` is kept as the component `description`.
|
|
42
|
+
* - Function parameters drop `$schema` and the description already given on
|
|
43
|
+
* the function itself, to keep the prompt small.
|
|
44
|
+
*/
|
|
45
|
+
function extractA2UICatalogSchemas(catalog) {
|
|
46
|
+
const components = Object.create(null);
|
|
47
|
+
const commonTypes = Object.create(null);
|
|
48
|
+
for (const [name, component] of catalog.components) {
|
|
49
|
+
const schema = serializeA2UISchema(component.schema, commonTypes);
|
|
50
|
+
const properties = schema.properties ?? {};
|
|
51
|
+
const required = schema.required ?? [];
|
|
52
|
+
components[name] = {
|
|
53
|
+
...typeof schema.description === "string" ? { description: schema.description } : {},
|
|
54
|
+
allOf: [{ $ref: "common_types.json#/$defs/ComponentCommon" }, {
|
|
55
|
+
properties: {
|
|
56
|
+
component: { const: name },
|
|
57
|
+
...properties
|
|
58
|
+
},
|
|
59
|
+
required: ["component", ...required]
|
|
60
|
+
}]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const functions = catalogFunctions(catalog.functions).map((fn) => {
|
|
64
|
+
const { description, ...parameters } = serializeA2UISchema(fn.schema, commonTypes);
|
|
65
|
+
return {
|
|
66
|
+
name: fn.name,
|
|
67
|
+
...typeof description === "string" ? { description } : {},
|
|
68
|
+
returnType: fn.returnType ?? "any",
|
|
69
|
+
parameters
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
const theme = catalog.themeSchema ? serializeA2UISchema(catalog.themeSchema, commonTypes).properties : void 0;
|
|
73
|
+
return {
|
|
74
|
+
catalogId: catalog.id,
|
|
75
|
+
components,
|
|
76
|
+
...functions.length > 0 ? { functions } : {},
|
|
77
|
+
...theme ? { theme } : {},
|
|
78
|
+
...Object.keys(commonTypes).length > 0 ? { "common_types.json": { $defs: commonTypes } } : {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Build a context string describing the catalog's id and the components it
|
|
83
|
+
* adds beyond the basic catalog.
|
|
84
|
+
*
|
|
85
|
+
* Schemas are serialized as in {@link extractA2UICatalogSchemas}, with the
|
|
86
|
+
* common types they reference listed once after the components.
|
|
87
|
+
*
|
|
88
|
+
* When `options.includeSchema` is `false`, custom components are listed by name
|
|
89
|
+
* only and their JSON schemas are omitted.
|
|
90
|
+
*/
|
|
91
|
+
function buildA2UICatalogContextValue(catalog, basicComponentNames, options) {
|
|
92
|
+
const lines = ["Available A2UI catalog:"];
|
|
93
|
+
if (catalog.id === A2UI_BASIC_CATALOG_ID) {
|
|
94
|
+
lines.push(`- ${catalog.id} (basic catalog)`);
|
|
95
|
+
return lines.join("\n");
|
|
96
|
+
}
|
|
97
|
+
const isSuperset = [...basicComponentNames].every((name) => catalog.components.has(name));
|
|
98
|
+
lines.push(`- ${catalog.id}`);
|
|
99
|
+
if (isSuperset) lines.push(" Extends the basic catalog with all standard components plus:");
|
|
100
|
+
else {
|
|
101
|
+
lines.push(" Custom catalog (does NOT include all basic components).");
|
|
102
|
+
lines.push(" Custom components:");
|
|
103
|
+
}
|
|
104
|
+
const commonTypes = Object.create(null);
|
|
105
|
+
for (const [name, component] of catalog.components) {
|
|
106
|
+
if (basicComponentNames.has(name)) continue;
|
|
107
|
+
if (options?.includeSchema === false) {
|
|
108
|
+
lines.push(` - ${name}`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
lines.push(` - ${name}:`);
|
|
112
|
+
lines.push(indented(serializeA2UISchema(component.schema, commonTypes)));
|
|
113
|
+
}
|
|
114
|
+
if (Object.keys(commonTypes).length > 0) {
|
|
115
|
+
lines.push(" Common types referenced above (common_types.json#/$defs):");
|
|
116
|
+
lines.push(indented(commonTypes));
|
|
117
|
+
}
|
|
118
|
+
return lines.join("\n");
|
|
119
|
+
}
|
|
120
|
+
/** JSON for the catalog context value, indented under a list item. */
|
|
121
|
+
function indented(value) {
|
|
122
|
+
return ` ${JSON.stringify(value, null, 2).split("\n").join("\n ")}`;
|
|
123
|
+
}
|
|
124
|
+
/** Raw zod-to-json-schema output per Zod schema, stored as JSON text. */
|
|
125
|
+
const serializedSchemas = /* @__PURE__ */ new WeakMap();
|
|
126
|
+
/**
|
|
127
|
+
* Convert one A2UI Zod schema to JSON Schema 2019-09, inlining reused schemas
|
|
128
|
+
* and resolving `REF:` markers (see {@link extractA2UICatalogSchemas}). The
|
|
129
|
+
* shapes behind `common_types.json` refs are recorded in `commonTypes`; pass
|
|
130
|
+
* the same map for every schema of one payload.
|
|
131
|
+
*
|
|
132
|
+
* The raw conversion is cached per schema object as JSON text, and every call
|
|
133
|
+
* parses a fresh copy. The JSON round-trip, unlike structuredClone, never
|
|
134
|
+
* throws on values such as a function or a Vue reactive proxy in a
|
|
135
|
+
* `.default()`, and yields exactly what the agent receives.
|
|
136
|
+
*/
|
|
137
|
+
function serializeA2UISchema(schema, commonTypes = Object.create(null)) {
|
|
138
|
+
const key = typeof schema === "object" && schema !== null ? schema : null;
|
|
139
|
+
let serialized = key ? serializedSchemas.get(key) : void 0;
|
|
140
|
+
if (serialized === void 0) {
|
|
141
|
+
const jsonSchema = zodToJsonSchema(schema, {
|
|
142
|
+
target: "jsonSchema2019-09",
|
|
143
|
+
$refStrategy: "none",
|
|
144
|
+
override: (_def, refs, seen, forceResolution) => seen && !forceResolution && seen.path.length < refs.currentPath.length && seen.path.every((part, i) => refs.currentPath[i] === part) ? {} : ignoreOverride
|
|
145
|
+
});
|
|
146
|
+
delete jsonSchema.$schema;
|
|
147
|
+
serialized = JSON.stringify(jsonSchema);
|
|
148
|
+
if (key) serializedSchemas.set(key, serialized);
|
|
149
|
+
}
|
|
150
|
+
const root = JSON.parse(serialized);
|
|
151
|
+
const marker = parseRefMarker(root.description);
|
|
152
|
+
if (marker) {
|
|
153
|
+
delete root.description;
|
|
154
|
+
if (marker.description) root.description = marker.description;
|
|
155
|
+
}
|
|
156
|
+
return resolveSubschemas(root, commonTypes);
|
|
157
|
+
}
|
|
158
|
+
/** Keywords whose value is a subschema, or an array of subschemas. */
|
|
159
|
+
const SUBSCHEMA_KEYWORDS = [
|
|
160
|
+
"items",
|
|
161
|
+
"additionalItems",
|
|
162
|
+
"additionalProperties",
|
|
163
|
+
"unevaluatedItems",
|
|
164
|
+
"unevaluatedProperties",
|
|
165
|
+
"contains",
|
|
166
|
+
"propertyNames",
|
|
167
|
+
"not",
|
|
168
|
+
"if",
|
|
169
|
+
"then",
|
|
170
|
+
"else",
|
|
171
|
+
"allOf",
|
|
172
|
+
"anyOf",
|
|
173
|
+
"oneOf",
|
|
174
|
+
"prefixItems"
|
|
175
|
+
];
|
|
176
|
+
/** Keywords whose value maps names to subschemas. */
|
|
177
|
+
const SUBSCHEMA_MAP_KEYWORDS = [
|
|
178
|
+
"properties",
|
|
179
|
+
"patternProperties",
|
|
180
|
+
"dependentSchemas",
|
|
181
|
+
"$defs",
|
|
182
|
+
"definitions"
|
|
183
|
+
];
|
|
184
|
+
const COMMON_TYPE_REF = /^common_types\.json#\/\$defs\/([^/]+)$/;
|
|
185
|
+
function isObject(value) {
|
|
186
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Split a `REF:<ref>|<description>` marker at its first `|`, so a description
|
|
190
|
+
* containing `|` is kept whole. The convention comes from
|
|
191
|
+
* `MessageProcessor.processRefs` in `@a2ui/web_core`.
|
|
192
|
+
*/
|
|
193
|
+
function parseRefMarker(description) {
|
|
194
|
+
if (typeof description !== "string" || !description.startsWith("REF:")) return;
|
|
195
|
+
const body = description.slice(4);
|
|
196
|
+
const separator = body.indexOf("|");
|
|
197
|
+
return separator === -1 ? { ref: body } : {
|
|
198
|
+
ref: body.slice(0, separator),
|
|
199
|
+
description: body.slice(separator + 1)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Resolve `REF:` markers in a schema's subschemas, innermost first, so a
|
|
204
|
+
* stored common type refers to the types it contains by bare `$ref` too.
|
|
205
|
+
*
|
|
206
|
+
* Only schema-valued keywords are traversed, so literal values under
|
|
207
|
+
* `default`, `const`, `enum` or `examples` are never rewritten.
|
|
208
|
+
*/
|
|
209
|
+
function resolveSubschemas(node, commonTypes) {
|
|
210
|
+
const resolve = (value) => Array.isArray(value) ? value.map(resolve) : isObject(value) ? resolveRefMarker(resolveSubschemas(value, commonTypes), commonTypes) : value;
|
|
211
|
+
const out = { ...node };
|
|
212
|
+
for (const keyword of SUBSCHEMA_KEYWORDS) if (keyword in out) out[keyword] = resolve(out[keyword]);
|
|
213
|
+
for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
|
|
214
|
+
const map = out[keyword];
|
|
215
|
+
if (isObject(map)) out[keyword] = Object.fromEntries(Object.entries(map).map(([name, child]) => [name, resolve(child)]));
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Turn a node carrying a `REF:` marker into a bare `$ref`, recording the
|
|
221
|
+
* shape it replaced under its `common_types.json` name. A shape that differs
|
|
222
|
+
* from the one already recorded, or a ref outside `common_types.json`, stays
|
|
223
|
+
* inline next to the `$ref`.
|
|
224
|
+
*/
|
|
225
|
+
function resolveRefMarker(node, commonTypes) {
|
|
226
|
+
const marker = parseRefMarker(node.description);
|
|
227
|
+
if (!marker) return node;
|
|
228
|
+
const { description: _marker, ...shape } = node;
|
|
229
|
+
const ref = {
|
|
230
|
+
$ref: marker.ref,
|
|
231
|
+
...marker.description ? { description: marker.description } : {}
|
|
232
|
+
};
|
|
233
|
+
const name = COMMON_TYPE_REF.exec(marker.ref)?.[1];
|
|
234
|
+
if (name !== void 0) {
|
|
235
|
+
const known = commonTypes[name];
|
|
236
|
+
if (known === void 0) {
|
|
237
|
+
commonTypes[name] = shape;
|
|
238
|
+
return ref;
|
|
239
|
+
}
|
|
240
|
+
if (JSON.stringify(known) === JSON.stringify(shape)) return ref;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
...ref,
|
|
244
|
+
...shape
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Read a catalog's functions, tolerating catalog-shaped objects whose
|
|
249
|
+
* `functions` is missing, a plain object or an array, and skipping entries
|
|
250
|
+
* without a name or schema.
|
|
251
|
+
*/
|
|
252
|
+
function catalogFunctions(functions) {
|
|
253
|
+
if (typeof functions !== "object" || functions === null) return [];
|
|
254
|
+
return (functions instanceof Map ? [...functions.values()] : Array.isArray(functions) ? functions : Object.values(functions)).filter((fn) => typeof fn === "object" && fn !== null && typeof fn.name === "string" && typeof fn.schema === "object" && fn.schema !== null);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//#endregion
|
|
258
|
+
export { A2UI_BASIC_CATALOG_ID, A2UI_SCHEMA_CONTEXT_DESCRIPTION, buildA2UICatalogContextValue, extractA2UICatalogSchemas, serializeA2UISchema };
|
|
259
|
+
//# sourceMappingURL=a2ui-catalog-schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2ui-catalog-schema.mjs","names":[],"sources":["../src/a2ui-catalog-schema.ts"],"sourcesContent":["import { ignoreOverride, zodToJsonSchema } from \"zod-to-json-schema\";\n\n/**\n * Context description used to identify the A2UI component schema in\n * RunAgentInput.context. Must match the constant in @ag-ui/a2ui-middleware so\n * the middleware can overwrite a frontend-provided schema with a server-side one.\n */\nexport const A2UI_SCHEMA_CONTEXT_DESCRIPTION =\n \"A2UI Component Schema — available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.\";\n\n/** Id of the A2UI v0.9 basic catalog. */\nexport const A2UI_BASIC_CATALOG_ID =\n \"https://a2ui.org/specification/v0_9/basic_catalog.json\";\n\ntype JsonSchema = Record<string, unknown>;\n\n/**\n * The parts of an `@a2ui/web_core` v0.9 `Catalog` that the serializers read.\n * Typed structurally so this module does not depend on web_core, and so the\n * minimal catalog-shaped objects some apps pass in still work.\n */\nexport interface A2UICatalogSchemaSource {\n readonly id: string;\n readonly components: ReadonlyMap<string, { readonly schema: unknown }>;\n /** A `ReadonlyMap` on a real `Catalog`; anything else is tolerated. */\n readonly functions?: unknown;\n readonly themeSchema?: unknown;\n}\n\n/** One entry of {@link A2UIInlineCatalogSchema.functions}. */\nexport interface A2UIFunctionSchema {\n name: string;\n description?: string;\n returnType: string;\n parameters: JsonSchema;\n}\n\n/**\n * A2UI v0.9 inline catalog, the shape of `InlineCatalog` in\n * `@a2ui/web_core/v0_9`, sent to the agent as the component schema.\n */\nexport interface A2UIInlineCatalogSchema {\n catalogId: string;\n components: Record<string, JsonSchema>;\n functions?: A2UIFunctionSchema[];\n theme?: Record<string, JsonSchema>;\n /**\n * One copy of each common type the schemas reference, so every\n * `common_types.json#/$defs/<Name>` ref resolves within this payload.\n */\n \"common_types.json\"?: { $defs: A2UICommonTypes };\n}\n\n/** Common type shapes keyed by their `common_types.json` `$defs` name. */\nexport type A2UICommonTypes = Record<string, JsonSchema>;\n\n/**\n * Serialize a catalog's Zod schemas in the A2UI v0.9 inline catalog format.\n *\n * Each component composes `ComponentCommon` with its own properties, matching\n * the flat wire format the agent must produce:\n *\n * { \"Column\": { \"allOf\": [\n * { \"$ref\": \"common_types.json#/$defs/ComponentCommon\" },\n * { \"properties\": { \"component\": {\"const\":\"Column\"}, \"gap\": ..., \"children\": ... },\n * \"required\": [\"component\"] }\n * ]}}\n *\n * This follows `getClientCapabilities` in `@a2ui/web_core` with these\n * deliberate differences:\n *\n * - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which\n * would dangle once properties move under `allOf[1]`.\n * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but\n * the shape it replaced is kept once under\n * `\"common_types.json\": { \"$defs\": { <Name>: ... } }`. Every\n * `common_types.json#/$defs/<Name>` ref therefore resolves within the\n * payload, both for agents that only see it as prompt text and for SDKs\n * (such as Google's A2UI SDK used by ADK) that read the `$ref`. Each type is\n * stated once rather than at every use site, which keeps the payload small.\n * A use whose shape differs from the stored one keeps its shape inline next\n * to the `$ref`, so the agent never sees a looser type than the client\n * accepts.\n * - A `REF:` marker on a schema's root only sets its description; replacing\n * the root would drop every property.\n * - A component's root `.describe()` is kept as the component `description`.\n * - Function parameters drop `$schema` and the description already given on\n * the function itself, to keep the prompt small.\n */\nexport function extractA2UICatalogSchemas(\n catalog: A2UICatalogSchemaSource,\n): A2UIInlineCatalogSchema {\n // Null prototypes, so a component or type named `__proto__` is kept as an\n // entry.\n const components: Record<string, JsonSchema> = Object.create(null);\n const commonTypes: A2UICommonTypes = Object.create(null);\n\n for (const [name, component] of catalog.components) {\n const schema = serializeA2UISchema(component.schema, commonTypes);\n const properties = (schema.properties ?? {}) as Record<string, JsonSchema>;\n const required = (schema.required ?? []) as string[];\n\n components[name] = {\n ...(typeof schema.description === \"string\"\n ? { description: schema.description }\n : {}),\n allOf: [\n { $ref: \"common_types.json#/$defs/ComponentCommon\" },\n {\n properties: { component: { const: name }, ...properties },\n required: [\"component\", ...required],\n },\n ],\n };\n }\n\n const functions = catalogFunctions(catalog.functions).map((fn) => {\n const { description, ...parameters } = serializeA2UISchema(\n fn.schema,\n commonTypes,\n );\n return {\n name: fn.name,\n ...(typeof description === \"string\" ? { description } : {}),\n returnType: fn.returnType ?? \"any\",\n parameters,\n };\n });\n\n const theme = catalog.themeSchema\n ? (serializeA2UISchema(catalog.themeSchema, commonTypes).properties as\n | Record<string, JsonSchema>\n | undefined)\n : undefined;\n\n return {\n catalogId: catalog.id,\n components,\n ...(functions.length > 0 ? { functions } : {}),\n ...(theme ? { theme } : {}),\n ...(Object.keys(commonTypes).length > 0\n ? { \"common_types.json\": { $defs: commonTypes } }\n : {}),\n };\n}\n\n/**\n * Build a context string describing the catalog's id and the components it\n * adds beyond the basic catalog.\n *\n * Schemas are serialized as in {@link extractA2UICatalogSchemas}, with the\n * common types they reference listed once after the components.\n *\n * When `options.includeSchema` is `false`, custom components are listed by name\n * only and their JSON schemas are omitted.\n */\nexport function buildA2UICatalogContextValue(\n catalog: A2UICatalogSchemaSource,\n basicComponentNames: ReadonlySet<string>,\n options?: { includeSchema?: boolean },\n): string {\n const lines: string[] = [\"Available A2UI catalog:\"];\n\n if (catalog.id === A2UI_BASIC_CATALOG_ID) {\n lines.push(`- ${catalog.id} (basic catalog)`);\n return lines.join(\"\\n\");\n }\n\n const isSuperset = [...basicComponentNames].every((name) =>\n catalog.components.has(name),\n );\n\n lines.push(`- ${catalog.id}`);\n if (isSuperset) {\n lines.push(\n \" Extends the basic catalog with all standard components plus:\",\n );\n } else {\n lines.push(\" Custom catalog (does NOT include all basic components).\");\n lines.push(\" Custom components:\");\n }\n\n const commonTypes: A2UICommonTypes = Object.create(null);\n\n for (const [name, component] of catalog.components) {\n if (basicComponentNames.has(name)) continue;\n if (options?.includeSchema === false) {\n lines.push(` - ${name}`);\n continue;\n }\n lines.push(` - ${name}:`);\n lines.push(indented(serializeA2UISchema(component.schema, commonTypes)));\n }\n\n if (Object.keys(commonTypes).length > 0) {\n lines.push(\" Common types referenced above (common_types.json#/$defs):\");\n lines.push(indented(commonTypes));\n }\n\n return lines.join(\"\\n\");\n}\n\n/** JSON for the catalog context value, indented under a list item. */\nfunction indented(value: unknown): string {\n return ` ${JSON.stringify(value, null, 2).split(\"\\n\").join(\"\\n \")}`;\n}\n\n/** Raw zod-to-json-schema output per Zod schema, stored as JSON text. */\nconst serializedSchemas = new WeakMap<object, string>();\n\n/**\n * zod-to-json-schema's own parameter type. Casting to it (rather than to\n * `ZodTypeAny`) avoids a TS2589 \"excessively deep\" instantiation.\n */\ntype ZodSchemaArg = Parameters<typeof zodToJsonSchema>[0];\n\n/**\n * Convert one A2UI Zod schema to JSON Schema 2019-09, inlining reused schemas\n * and resolving `REF:` markers (see {@link extractA2UICatalogSchemas}). The\n * shapes behind `common_types.json` refs are recorded in `commonTypes`; pass\n * the same map for every schema of one payload.\n *\n * The raw conversion is cached per schema object as JSON text, and every call\n * parses a fresh copy. The JSON round-trip, unlike structuredClone, never\n * throws on values such as a function or a Vue reactive proxy in a\n * `.default()`, and yields exactly what the agent receives.\n */\nexport function serializeA2UISchema(\n schema: unknown,\n commonTypes: A2UICommonTypes = Object.create(null),\n): JsonSchema {\n const key = typeof schema === \"object\" && schema !== null ? schema : null;\n let serialized = key ? serializedSchemas.get(key) : undefined;\n if (serialized === undefined) {\n const jsonSchema = zodToJsonSchema(schema as ZodSchemaArg, {\n target: \"jsonSchema2019-09\",\n $refStrategy: \"none\",\n // With \"none\", zod-to-json-schema already turns a recursive reference\n // into `{}` (any), but logs a warning every time it does. Return `{}`\n // here directly so re-serializing a recursive catalog stays quiet.\n override: (_def, refs, seen, forceResolution) =>\n seen &&\n !forceResolution &&\n seen.path.length < refs.currentPath.length &&\n seen.path.every((part, i) => refs.currentPath[i] === part)\n ? {}\n : ignoreOverride,\n }) as JsonSchema;\n delete jsonSchema.$schema;\n serialized = JSON.stringify(jsonSchema);\n if (key) serializedSchemas.set(key, serialized);\n }\n\n const root = JSON.parse(serialized) as JsonSchema;\n const marker = parseRefMarker(root.description);\n if (marker) {\n delete root.description;\n if (marker.description) root.description = marker.description;\n }\n return resolveSubschemas(root, commonTypes);\n}\n\n/** Keywords whose value is a subschema, or an array of subschemas. */\nconst SUBSCHEMA_KEYWORDS = [\n \"items\",\n \"additionalItems\",\n \"additionalProperties\",\n \"unevaluatedItems\",\n \"unevaluatedProperties\",\n \"contains\",\n \"propertyNames\",\n \"not\",\n \"if\",\n \"then\",\n \"else\",\n \"allOf\",\n \"anyOf\",\n \"oneOf\",\n \"prefixItems\",\n];\n/** Keywords whose value maps names to subschemas. */\nconst SUBSCHEMA_MAP_KEYWORDS = [\n \"properties\",\n \"patternProperties\",\n \"dependentSchemas\",\n \"$defs\",\n \"definitions\",\n];\n\nconst COMMON_TYPE_REF = /^common_types\\.json#\\/\\$defs\\/([^/]+)$/;\n\nfunction isObject(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Split a `REF:<ref>|<description>` marker at its first `|`, so a description\n * containing `|` is kept whole. The convention comes from\n * `MessageProcessor.processRefs` in `@a2ui/web_core`.\n */\nfunction parseRefMarker(\n description: unknown,\n): { ref: string; description?: string } | undefined {\n if (typeof description !== \"string\" || !description.startsWith(\"REF:\")) {\n return undefined;\n }\n const body = description.slice(4);\n const separator = body.indexOf(\"|\");\n return separator === -1\n ? { ref: body }\n : { ref: body.slice(0, separator), description: body.slice(separator + 1) };\n}\n\n/**\n * Resolve `REF:` markers in a schema's subschemas, innermost first, so a\n * stored common type refers to the types it contains by bare `$ref` too.\n *\n * Only schema-valued keywords are traversed, so literal values under\n * `default`, `const`, `enum` or `examples` are never rewritten.\n */\nfunction resolveSubschemas(\n node: JsonSchema,\n commonTypes: A2UICommonTypes,\n): JsonSchema {\n const resolve = (value: unknown): unknown =>\n Array.isArray(value)\n ? value.map(resolve)\n : isObject(value)\n ? resolveRefMarker(resolveSubschemas(value, commonTypes), commonTypes)\n : value;\n\n const out: JsonSchema = { ...node };\n for (const keyword of SUBSCHEMA_KEYWORDS) {\n if (keyword in out) out[keyword] = resolve(out[keyword]);\n }\n for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {\n const map = out[keyword];\n if (isObject(map)) {\n out[keyword] = Object.fromEntries(\n Object.entries(map).map(([name, child]) => [name, resolve(child)]),\n );\n }\n }\n return out;\n}\n\n/**\n * Turn a node carrying a `REF:` marker into a bare `$ref`, recording the\n * shape it replaced under its `common_types.json` name. A shape that differs\n * from the one already recorded, or a ref outside `common_types.json`, stays\n * inline next to the `$ref`.\n */\nfunction resolveRefMarker(\n node: JsonSchema,\n commonTypes: A2UICommonTypes,\n): JsonSchema {\n const marker = parseRefMarker(node.description);\n if (!marker) return node;\n\n const { description: _marker, ...shape } = node;\n const ref: JsonSchema = {\n $ref: marker.ref,\n ...(marker.description ? { description: marker.description } : {}),\n };\n const name = COMMON_TYPE_REF.exec(marker.ref)?.[1];\n if (name !== undefined) {\n const known = commonTypes[name];\n if (known === undefined) {\n commonTypes[name] = shape;\n return ref;\n }\n if (JSON.stringify(known) === JSON.stringify(shape)) return ref;\n }\n return { ...ref, ...shape };\n}\n\ninterface CatalogFunction {\n name: string;\n returnType?: string;\n schema: unknown;\n}\n\n/**\n * Read a catalog's functions, tolerating catalog-shaped objects whose\n * `functions` is missing, a plain object or an array, and skipping entries\n * without a name or schema.\n */\nfunction catalogFunctions(functions: unknown): CatalogFunction[] {\n if (typeof functions !== \"object\" || functions === null) return [];\n const entries =\n functions instanceof Map\n ? [...functions.values()]\n : Array.isArray(functions)\n ? functions\n : Object.values(functions);\n return entries.filter(\n (fn): fn is CatalogFunction =>\n typeof fn === \"object\" &&\n fn !== null &&\n typeof fn.name === \"string\" &&\n typeof fn.schema === \"object\" &&\n fn.schema !== null,\n );\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,kCACX;;AAGF,MAAa,wBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EF,SAAgB,0BACd,SACyB;CAGzB,MAAM,aAAyC,OAAO,OAAO,KAAK;CAClE,MAAM,cAA+B,OAAO,OAAO,KAAK;AAExD,MAAK,MAAM,CAAC,MAAM,cAAc,QAAQ,YAAY;EAClD,MAAM,SAAS,oBAAoB,UAAU,QAAQ,YAAY;EACjE,MAAM,aAAc,OAAO,cAAc,EAAE;EAC3C,MAAM,WAAY,OAAO,YAAY,EAAE;AAEvC,aAAW,QAAQ;GACjB,GAAI,OAAO,OAAO,gBAAgB,WAC9B,EAAE,aAAa,OAAO,aAAa,GACnC,EAAE;GACN,OAAO,CACL,EAAE,MAAM,4CAA4C,EACpD;IACE,YAAY;KAAE,WAAW,EAAE,OAAO,MAAM;KAAE,GAAG;KAAY;IACzD,UAAU,CAAC,aAAa,GAAG,SAAS;IACrC,CACF;GACF;;CAGH,MAAM,YAAY,iBAAiB,QAAQ,UAAU,CAAC,KAAK,OAAO;EAChE,MAAM,EAAE,aAAa,GAAG,eAAe,oBACrC,GAAG,QACH,YACD;AACD,SAAO;GACL,MAAM,GAAG;GACT,GAAI,OAAO,gBAAgB,WAAW,EAAE,aAAa,GAAG,EAAE;GAC1D,YAAY,GAAG,cAAc;GAC7B;GACD;GACD;CAEF,MAAM,QAAQ,QAAQ,cACjB,oBAAoB,QAAQ,aAAa,YAAY,CAAC,aAGvD;AAEJ,QAAO;EACL,WAAW,QAAQ;EACnB;EACA,GAAI,UAAU,SAAS,IAAI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,OACC,OAAO,OAAO,YACd,OAAO,QACP,OAAO,GAAG,SAAS,YACnB,OAAO,GAAG,WAAW,YACrB,GAAG,WAAW,KACjB"}
|
package/dist/a2ui-envelope.cjs
CHANGED
|
@@ -72,7 +72,7 @@ function isExtensions(value) {
|
|
|
72
72
|
return require_is_record.isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
73
73
|
}
|
|
74
74
|
function isEnvelope(value) {
|
|
75
|
-
return require_is_record.isRecord(value) && isCapabilities(value["
|
|
75
|
+
return require_is_record.isRecord(value) && isCapabilities(value["1.0"]) && require_is_record.isRecord(value.metadata) && isExtensions(value.metadata.extensions);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Reads the generative UI envelope from the `forwardedProps` of a run.
|
|
@@ -127,7 +127,7 @@ function readCopilotKitUIEnvelope(forwardedProps) {
|
|
|
127
127
|
* ```
|
|
128
128
|
*/
|
|
129
129
|
function envelopeToManifest(envelope) {
|
|
130
|
-
const { supportedCatalogIds, inlineCatalogs } = envelope["
|
|
130
|
+
const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
|
|
131
131
|
const catalogId = supportedCatalogIds[0];
|
|
132
132
|
const catalog = inlineCatalogs?.find((entry) => entry.catalogId === catalogId);
|
|
133
133
|
const extensions = envelope.metadata.extensions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-envelope.cjs","names":["isRecord","GENERATIVE_UI_MAX_TARGET_COMPONENTS","GENERATIVE_UI_MAX_SUMMARY_REJECTIONS","GENERATIVE_UI_MAX_REJECTION_LENGTH"],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"v1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"v1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"v1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"v1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"v1.0\"];\n const catalogId = supportedCatalogIds[0];\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,WACP,OACA,SAC4B;AAC5B,QAAOA,2BAAS,MAAM,IAAI,OAAO,OAAO,MAAM,CAAC,MAAM,QAAQ;;;AAI/D,SAAS,cAAc,OAAuD;AAC5E,QACEA,2BAAS,MAAM,IACfA,2BAAS,MAAM,WAAW,IAC1B,iBAAiB,MAAM,YAAY;;AAIvC,SAAS,WAAW,OAAgD;AAClE,QAAO,UAAU,YAAY,UAAU;;;;;;AAOzC,SAAS,c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C,MAAM,WAAW,UAAU;AAC3B,QAAO,WAAW,SAAS,GAAG,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B3C,SAAgB,mBAAmB,UAAgC;CACjE,MAAM,EAAE,qBAAqB,mBAAmB,SAAS;CACzD,MAAM,YAAY,oBAAoB;CACtC,MAAM,UAAU,gBAAgB,MAC7B,UAAU,MAAM,cAAc,UAChC;CACD,MAAM,aAAa,SAAS,SAAS;AASrC,QAAO;EAPL;EACA,YAAY;EACZ,YAAY,SAAS,cAAc,EAAE;EACrC,WAAW,SAAS,aAAa,EAAE;EACnC,SAAS,WAAW;EACpB,UAAU,WAAW;EAIrB,WAAW,WAAW;EACtB,aAAa,WAAW;EACxB,cAAc,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
|
|
1
|
+
{"version":3,"file":"a2ui-envelope.cjs","names":["isRecord","GENERATIVE_UI_MAX_TARGET_COMPONENTS","GENERATIVE_UI_MAX_SUMMARY_REJECTIONS","GENERATIVE_UI_MAX_REJECTION_LENGTH"],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"1.0\"];\n const catalogId = supportedCatalogIds[0];\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,WACP,OACA,SAC4B;AAC5B,QAAOA,2BAAS,MAAM,IAAI,OAAO,OAAO,MAAM,CAAC,MAAM,QAAQ;;;AAI/D,SAAS,cAAc,OAAuD;AAC5E,QACEA,2BAAS,MAAM,IACfA,2BAAS,MAAM,WAAW,IAC1B,iBAAiB,MAAM,YAAY;;AAIvC,SAAS,WAAW,OAAgD;AAClE,QAAO,UAAU,YAAY,UAAU;;;;;;AAOzC,SAAS,cAAc,OAAkD;AACvE,QACEA,2BAAS,MAAM,KACd,MAAM,eAAe,UAAaA,2BAAS,MAAM,WAAW,MAC5D,MAAM,aAAa,UACjB,MAAM,QAAQ,MAAM,SAAS,IAC5B,MAAM,SAAS,OAAO,SAAS,OAAO,SAAS,SAAS;;AAIhE,SAAS,oBACP,OACwC;AACxC,KACE,CAACA,2BAAS,MAAM,IAChB,CAAC,cAAc,MAAM,MAAM,IAC3B,CAAC,iBAAiB,MAAM,YAAY,IACnC,MAAM,WAAW,UAAa,CAAC,WAAW,MAAM,QAAQ,cAAc,IACtE,MAAM,UAAU,UAAa,CAAC,WAAW,MAAM,OAAO,WAAW,CAElE,QAAO;CACT,MAAM,QAAQ,MAAM;A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c,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
|
package/dist/a2ui-envelope.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ declare const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;
|
|
|
8
8
|
/** What the client renders and calls, and how the model must write UI. */
|
|
9
9
|
interface CopilotKitUIEnvelope {
|
|
10
10
|
/** The A2UI v1.0 renderer capabilities. */
|
|
11
|
-
"
|
|
11
|
+
"1.0": {
|
|
12
12
|
/**
|
|
13
13
|
* The catalog that the client renders comes first, then the catalogs of
|
|
14
14
|
* its `extends`. An operation can name any of them.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-envelope.d.cts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,
|
|
1
|
+
{"version":3,"file":"a2ui-envelope.d.cts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,KAAA;IALwC;;;;IAUtC,mBAAA;IACA,cAAA,GAAiB,KAAA;MACf,SAAA;MACA,eAAA,SAEa;MAAb,UAAA,GAAa,MAAA,SAAe,6BAAA,GAEjB;MAAX,SAAA,EAAW,MAAA,SAAe,4BAAA,GAQA;MAN1B,YAAA;IAAA;EAAA;EAGJ,QAAA;IACE,UAAA;MAlBF,8BAoBI,iBAAA,SAA0B,6BAAA,EAd5B;MAgBE,oBAAA;MACA,kBAAA,EAAoB,oBAAA;MACpB,mBAAA,EAAqB,oBAAA,cAdrB;MAgBA,sBAAA;MAhB4B;;;;MAqB5B,iBAAA,GAAoB,iBAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;AA0L1B;;;;;AAmCA;;iBAnCgB,wBAAA,CAAyB,cAAA,YAAuB,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmChD,kBAAA,CAAmB,QAAA,EAAU,oBAAA"}
|
package/dist/a2ui-envelope.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ declare const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;
|
|
|
8
8
|
/** What the client renders and calls, and how the model must write UI. */
|
|
9
9
|
interface CopilotKitUIEnvelope {
|
|
10
10
|
/** The A2UI v1.0 renderer capabilities. */
|
|
11
|
-
"
|
|
11
|
+
"1.0": {
|
|
12
12
|
/**
|
|
13
13
|
* The catalog that the client renders comes first, then the catalogs of
|
|
14
14
|
* its `extends`. An operation can name any of them.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-envelope.d.mts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,
|
|
1
|
+
{"version":3,"file":"a2ui-envelope.d.mts","names":[],"sources":["../src/a2ui-envelope.ts"],"mappings":";;;;cAuBa,8BAAA;AAAb;AAAA,cAGa,6BAAA;;UAGI,oBAAA;EAN0B;EAQzC,KAAA;IALwC;;;;IAUtC,mBAAA;IACA,cAAA,GAAiB,KAAA;MACf,SAAA;MACA,eAAA,SAEa;MAAb,UAAA,GAAa,MAAA,SAAe,6BAAA,GAEjB;MAAX,SAAA,EAAW,MAAA,SAAe,4BAAA,GAQA;MAN1B,YAAA;IAAA;EAAA;EAGJ,QAAA;IACE,UAAA;MAlBF,8BAoBI,iBAAA,SAA0B,6BAAA,EAd5B;MAgBE,oBAAA;MACA,kBAAA,EAAoB,oBAAA;MACpB,mBAAA,EAAqB,oBAAA,cAdrB;MAgBA,sBAAA;MAhB4B;;;;MAqB5B,iBAAA,GAAoB,iBAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;AA0L1B;;;;;AAmCA;;iBAnCgB,wBAAA,CAAyB,cAAA,YAAuB,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmChD,kBAAA,CAAmB,QAAA,EAAU,oBAAA"}
|
package/dist/a2ui-envelope.mjs
CHANGED
|
@@ -72,7 +72,7 @@ function isExtensions(value) {
|
|
|
72
72
|
return isRecord(value) && value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT && (value.copilotkit_transport === "tool" || value.copilotkit_transport === "markdown") && Array.isArray(value.copilotkit_targets) && value.copilotkit_targets.every(isTarget) && isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) && typeof value.copilotkit_contextSent === "boolean";
|
|
73
73
|
}
|
|
74
74
|
function isEnvelope(value) {
|
|
75
|
-
return isRecord(value) && isCapabilities(value["
|
|
75
|
+
return isRecord(value) && isCapabilities(value["1.0"]) && isRecord(value.metadata) && isExtensions(value.metadata.extensions);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Reads the generative UI envelope from the `forwardedProps` of a run.
|
|
@@ -127,7 +127,7 @@ function readCopilotKitUIEnvelope(forwardedProps) {
|
|
|
127
127
|
* ```
|
|
128
128
|
*/
|
|
129
129
|
function envelopeToManifest(envelope) {
|
|
130
|
-
const { supportedCatalogIds, inlineCatalogs } = envelope["
|
|
130
|
+
const { supportedCatalogIds, inlineCatalogs } = envelope["1.0"];
|
|
131
131
|
const catalogId = supportedCatalogIds[0];
|
|
132
132
|
const catalog = inlineCatalogs?.find((entry) => entry.catalogId === catalogId);
|
|
133
133
|
const extensions = envelope.metadata.extensions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"a2ui-envelope.mjs","names":[],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"v1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"v1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"v1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"v1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"v1.0\"];\n const catalogId = supportedCatalogIds[0];\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAa,iCAAiC;;AAG9C,MAAa,gCAAgC;AA8C7C,SAAS,iBAAiB,OAAgB;AACxC,QAAO,UAAU,UAAa,OAAO,UAAU;;AAGjD,SAAS,iBAAiB,OAAiC;AACzD,QAAO,OAAO,UAAU,YAAY,UAAU;;AAGhD,SAAS,WACP,OACA,SAC4B;AAC5B,QAAO,SAAS,MAAM,IAAI,OAAO,OAAO,MAAM,CAAC,MAAM,QAAQ;;;AAI/D,SAAS,cAAc,OAAuD;AAC5E,QACE,SAAS,MAAM,IACf,SAAS,MAAM,WAAW,IAC1B,iBAAiB,MAAM,YAAY;;AAIvC,SAAS,WAAW,OAAgD;AAClE,QAAO,UAAU,YAAY,UAAU;;;;;;AAOzC,SAAS,cAAc,OAAkD;AACvE,QACE,SAAS,MAAM,KACd,MAAM,eAAe,UAAa,SAAS,MAAM,WAAW,MAC5D,MAAM,aAAa,UACjB,MAAM,QAAQ,MAAM,SAAS,IAC5B,MAAM,SAAS,OAAO,SAA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AoB;CACtC,MAAM,UAAU,gBAAgB,MAC7B,UAAU,MAAM,cAAc,UAChC;CACD,MAAM,aAAa,SAAS,SAAS;AASrC,QAAO;EAPL;EACA,YAAY;EACZ,YAAY,SAAS,cAAc,EAAE;EACrC,WAAW,SAAS,aAAa,EAAE;EACnC,SAAS,WAAW;EACpB,UAAU,WAAW;EAIrB,WAAW,WAAW;EACtB,aAAa,WAAW;EACxB,cAAc,SAAS;EACvB,eAAe,SAAS,eAAe;EACvC,GAAI,WAAW,sBAAsB,SACjC,EAAE,GACF,EAAE,QAAQ,WAAW,mBAAmB;EAC7C"}
|
|
1
|
+
{"version":3,"file":"a2ui-envelope.mjs","names":[],"sources":["../src/a2ui-envelope.ts"],"sourcesContent":["/**\n * The generative UI envelope that the client sends on every run as\n * `forwardedProps.copilotkit.ui`. It has the A2UI v1.0 renderer capabilities\n * shape, so a backend that speaks A2UI v1.0 can read the catalog as it is.\n * CopilotKit data goes in `metadata.extensions`, under `copilotkit_` keys.\n * The runtime reads it to pick the transport and to build the guide.\n */\nimport {\n GENERATIVE_UI_MAX_REJECTION_LENGTH,\n GENERATIVE_UI_MAX_SUMMARY_REJECTIONS,\n GENERATIVE_UI_MAX_TARGET_COMPONENTS,\n} from \"./generative-ui/types\";\nimport type {\n A2UIActionMessage,\n GenerativeUIComponentManifest,\n GenerativeUIFunctionManifest,\n GenerativeUIManifest,\n GenerativeUISurfaceSummary,\n GenerativeUITarget,\n} from \"./generative-ui/types\";\nimport { isRecord } from \"./generative-ui/is-record\";\n\n/** Top-level `forwardedProps` key that holds the CopilotKit run properties. */\nexport const COPILOTKIT_FORWARDED_PROPS_KEY = \"copilotkit\";\n\n/** Version of the envelope shape (not of the UI protocol that it carries). */\nexport const COPILOTKIT_UI_ENVELOPE_FORMAT = 3;\n\n/** What the client renders and calls, and how the model must write UI. */\nexport interface CopilotKitUIEnvelope {\n /** The A2UI v1.0 renderer capabilities. */\n \"1.0\": {\n /**\n * The catalog that the client renders comes first, then the catalogs of\n * its `extends`. An operation can name any of them.\n */\n supportedCatalogIds: string[];\n inlineCatalogs?: Array<{\n catalogId: string;\n protocolVersion: \"1.0\";\n /** Not there when the client is set up with `includeCatalog: false`. */\n components?: Record<string, GenerativeUIComponentManifest>;\n /** The app functions that are mounted now. */\n functions: Record<string, GenerativeUIFunctionManifest>;\n /** The markdown guideline. Only the markdown transport sends it. */\n instructions?: string;\n }>;\n };\n metadata: {\n extensions: {\n /** Envelope shape version. */\n copilotkit_format: typeof COPILOTKIT_UI_ENVELOPE_FORMAT;\n /** \"tool\": the model calls the render tool. \"markdown\": the model writes ```a2ui fences. */\n copilotkit_transport: \"tool\" | \"markdown\";\n copilotkit_targets: GenerativeUIManifest[\"targets\"];\n copilotkit_surfaces: GenerativeUIManifest[\"surfaces\"];\n /** True when the client also sent the guide as context entries on this run. */\n copilotkit_contextSent: boolean;\n /**\n * The A2UI action that started this run, when a user event did: the\n * structured form of the user message that the event added.\n */\n copilotkit_action?: A2UIActionMessage;\n };\n };\n}\n\ntype InlineCatalog = NonNullable<\n CopilotKitUIEnvelope[\"1.0\"][\"inlineCatalogs\"]\n>[number];\ntype Extensions = CopilotKitUIEnvelope[\"metadata\"][\"extensions\"];\n\nfunction isOptionalString(value: unknown) {\n return value === undefined || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value !== \"\";\n}\n\nfunction isRecordOf<T>(\n value: unknown,\n isEntry: (entry: unknown) => entry is T,\n): value is Record<string, T> {\n return isRecord(value) && Object.values(value).every(isEntry);\n}\n\n/** A function, or an event of a component: a description and a parameter schema. */\nfunction isSchemaEntry(value: unknown): value is GenerativeUIFunctionManifest {\n return (\n isRecord(value) &&\n isRecord(value.parameters) &&\n isOptionalString(value.description)\n );\n}\n\nfunction isSlotKind(value: unknown): value is \"single\" | \"multiple\" {\n return value === \"single\" || value === \"multiple\";\n}\n\n/**\n * `validateOperation` reads `properties` and `required` of a props schema,\n * so those two must have the right shape when they are there.\n */\nfunction isPropsSchema(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n (value.properties === undefined || isRecord(value.properties)) &&\n (value.required === undefined ||\n (Array.isArray(value.required) &&\n value.required.every((name) => typeof name === \"string\")))\n );\n}\n\nfunction isComponentManifest(\n value: unknown,\n): value is GenerativeUIComponentManifest {\n if (\n !isRecord(value) ||\n !isPropsSchema(value.props) ||\n !isOptionalString(value.description) ||\n (value.events !== undefined && !isRecordOf(value.events, isSchemaEntry)) ||\n (value.slots !== undefined && !isRecordOf(value.slots, isSlotKind))\n )\n return false;\n const order = value.parameterOrder;\n if (order === undefined) return true;\n const keys = new Set([\n ...Object.keys(value.props.properties ?? {}),\n ...Object.keys(value.slots ?? {}),\n ...Object.keys(value.events ?? {}),\n ]);\n return (\n Array.isArray(order) &&\n new Set(order).size === order.length &&\n order.every((key) => typeof key === \"string\" && keys.has(key))\n );\n}\n\nfunction isInlineCatalog(value: unknown): value is InlineCatalog {\n return (\n isRecord(value) &&\n isNonEmptyString(value.catalogId) &&\n value.protocolVersion === \"1.0\" &&\n (value.components === undefined ||\n isRecordOf(value.components, isComponentManifest)) &&\n isRecordOf(value.functions, isSchemaEntry) &&\n isOptionalString(value.instructions)\n );\n}\n\nfunction isCapabilities(value: unknown): value is CopilotKitUIEnvelope[\"1.0\"] {\n return (\n isRecord(value) &&\n Array.isArray(value.supportedCatalogIds) &&\n value.supportedCatalogIds.length > 0 &&\n value.supportedCatalogIds.every(isNonEmptyString) &&\n (value.inlineCatalogs === undefined ||\n (Array.isArray(value.inlineCatalogs) &&\n value.inlineCatalogs.every(isInlineCatalog)))\n );\n}\n\n/** A short list of component names. */\nfunction isComponentNameList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_TARGET_COMPONENTS &&\n value.every(isNonEmptyString)\n );\n}\n\nfunction isTarget(value: unknown): value is GenerativeUITarget {\n return (\n isRecord(value) &&\n isNonEmptyString(value.id) &&\n (value.kind === \"chat\" || value.kind === \"inline\") &&\n isOptionalString(value.description) &&\n (value.components === undefined || isComponentNameList(value.components))\n );\n}\n\n/** A short list of short strings. The summary limits keep the guide small. */\nfunction isRejectionList(value: unknown): value is string[] {\n return (\n Array.isArray(value) &&\n value.length <= GENERATIVE_UI_MAX_SUMMARY_REJECTIONS &&\n value.every(\n (entry) =>\n typeof entry === \"string\" &&\n entry.length <= GENERATIVE_UI_MAX_REJECTION_LENGTH,\n )\n );\n}\n\nfunction isSurfaceEntry(value: unknown): value is GenerativeUISurfaceSummary {\n return (\n isRecord(value) &&\n isNonEmptyString(value.target) &&\n (value.dataModel === undefined || isRecord(value.dataModel)) &&\n (value.rejected === undefined || isRejectionList(value.rejected)) &&\n (value.status === undefined ||\n value.status === \"deleted\" ||\n value.status === \"failed\")\n );\n}\n\n/** Checks the `copilotkit_` keys only. Other extensions can be there too. */\nfunction isExtensions(value: unknown): value is Extensions {\n return (\n isRecord(value) &&\n value.copilotkit_format === COPILOTKIT_UI_ENVELOPE_FORMAT &&\n (value.copilotkit_transport === \"tool\" ||\n value.copilotkit_transport === \"markdown\") &&\n Array.isArray(value.copilotkit_targets) &&\n value.copilotkit_targets.every(isTarget) &&\n isRecordOf(value.copilotkit_surfaces, isSurfaceEntry) &&\n typeof value.copilotkit_contextSent === \"boolean\"\n );\n}\n\nfunction isEnvelope(value: unknown): value is CopilotKitUIEnvelope {\n return (\n isRecord(value) &&\n isCapabilities(value[\"1.0\"]) &&\n isRecord(value.metadata) &&\n isExtensions(value.metadata.extensions)\n );\n}\n\n/**\n * Reads the generative UI envelope from the `forwardedProps` of a run.\n *\n * The envelope comes from the client, so it is not trusted: every field is\n * checked. Returns `undefined` when the envelope is not there, or when it is\n * malformed (for example a wrong `copilotkit_format` or\n * `copilotkit_transport`, or no catalog id).\n *\n * @param forwardedProps - The `forwardedProps` of the run input.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * if (envelope?.metadata.extensions.copilotkit_transport === \"markdown\") {\n * // The model writes ```a2ui fences. Add no render tool.\n * }\n * ```\n */\nexport function readCopilotKitUIEnvelope(forwardedProps: unknown) {\n if (!isRecord(forwardedProps)) return undefined;\n const namespace = forwardedProps[COPILOTKIT_FORWARDED_PROPS_KEY];\n if (!isRecord(namespace)) return undefined;\n const envelope = namespace.ui;\n return isEnvelope(envelope) ? envelope : undefined;\n}\n\n/**\n * Turns an envelope into the manifest that the runtime and the prompts use.\n *\n * The catalog is the first of `supportedCatalogIds`, and `catalogIds` lists\n * all of them. The components, functions, and instructions come from the\n * inline catalog of the first id.\n * With no such inline catalog, there are no components and no functions.\n *\n * The result also has:\n * - `transport` and `contextSent`, from the extensions.\n * - `instructions`, when the inline catalog has them.\n * - `hasComponents`: false when the client left the component schemas out.\n * The runtime cannot check operations without them.\n * - `action`: the A2UI action message of the user event that started the\n * run, when one did.\n *\n * @param envelope - An envelope from `readCopilotKitUIEnvelope`.\n *\n * @example\n * ```ts\n * const envelope = readCopilotKitUIEnvelope(input.forwardedProps);\n * const manifest = envelope && envelopeToManifest(envelope);\n * if (manifest?.transport === \"tool\" && manifest.hasComponents) {\n * // Add the render tool and validate operations against manifest.components.\n * }\n * ```\n */\nexport function envelopeToManifest(envelope: CopilotKitUIEnvelope) {\n const { supportedCatalogIds, inlineCatalogs } = envelope[\"1.0\"];\n const catalogId = supportedCatalogIds[0];\n const catalog = inlineCatalogs?.find(\n (entry) => entry.catalogId === catalogId,\n );\n const extensions = envelope.metadata.extensions;\n const manifest: GenerativeUIManifest = {\n catalogId,\n catalogIds: supportedCatalogIds,\n components: catalog?.components ?? {},\n functions: catalog?.functions ?? {},\n targets: extensions.copilotkit_targets,\n surfaces: extensions.copilotkit_surfaces,\n };\n return {\n ...manifest,\n transport: extensions.copilotkit_transport,\n contextSent: extensions.copilotkit_contextSent,\n instructions: catalog?.instructions,\n hasComponents: catalog?.components !== undefined,\n ...(extensions.copilotkit_action === undefined\n ? {}\n : { action: extensions.copilotkit_action }),\n };\n}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