@copilotkit/shared 1.84.0 → 1.84.2-canary.1793807121

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.
@@ -0,0 +1,264 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ let zod_to_json_schema = require("zod-to-json-schema");
3
+
4
+ //#region src/a2ui-catalog-schema.ts
5
+ /**
6
+ * Context description used to identify the A2UI component schema in
7
+ * RunAgentInput.context. Must match the constant in @ag-ui/a2ui-middleware so
8
+ * the middleware can overwrite a frontend-provided schema with a server-side one.
9
+ */
10
+ const A2UI_SCHEMA_CONTEXT_DESCRIPTION = "A2UI Component Schema — available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.";
11
+ /** Id of the A2UI v0.9 basic catalog. */
12
+ const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json";
13
+ /**
14
+ * Serialize a catalog's Zod schemas in the A2UI v0.9 inline catalog format.
15
+ *
16
+ * Each component composes `ComponentCommon` with its own properties, matching
17
+ * the flat wire format the agent must produce:
18
+ *
19
+ * { "Column": { "allOf": [
20
+ * { "$ref": "common_types.json#/$defs/ComponentCommon" },
21
+ * { "properties": { "component": {"const":"Column"}, "gap": ..., "children": ... },
22
+ * "required": ["component"] }
23
+ * ]}}
24
+ *
25
+ * This follows `getClientCapabilities` in `@a2ui/web_core` with these
26
+ * deliberate differences:
27
+ *
28
+ * - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which
29
+ * would dangle once properties move under `allOf[1]`.
30
+ * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but
31
+ * the shape it replaced is kept once under
32
+ * `"common_types.json": { "$defs": { <Name>: ... } }`. Every
33
+ * `common_types.json#/$defs/<Name>` ref therefore resolves within the
34
+ * payload, both for agents that only see it as prompt text and for SDKs
35
+ * (such as Google's A2UI SDK used by ADK) that read the `$ref`. Each type is
36
+ * stated once rather than at every use site, which keeps the payload small.
37
+ * A use whose shape differs from the stored one keeps its shape inline next
38
+ * to the `$ref`, so the agent never sees a looser type than the client
39
+ * accepts.
40
+ * - A `REF:` marker on a schema's root only sets its description; replacing
41
+ * the root would drop every property.
42
+ * - A component's root `.describe()` is kept as the component `description`.
43
+ * - Function parameters drop `$schema` and the description already given on
44
+ * the function itself, to keep the prompt small.
45
+ */
46
+ function extractA2UICatalogSchemas(catalog) {
47
+ const components = Object.create(null);
48
+ const commonTypes = Object.create(null);
49
+ for (const [name, component] of catalog.components) {
50
+ const schema = serializeA2UISchema(component.schema, commonTypes);
51
+ const properties = schema.properties ?? {};
52
+ const required = schema.required ?? [];
53
+ components[name] = {
54
+ ...typeof schema.description === "string" ? { description: schema.description } : {},
55
+ allOf: [{ $ref: "common_types.json#/$defs/ComponentCommon" }, {
56
+ properties: {
57
+ component: { const: name },
58
+ ...properties
59
+ },
60
+ required: ["component", ...required]
61
+ }]
62
+ };
63
+ }
64
+ const functions = catalogFunctions(catalog.functions).map((fn) => {
65
+ const { description, ...parameters } = serializeA2UISchema(fn.schema, commonTypes);
66
+ return {
67
+ name: fn.name,
68
+ ...typeof description === "string" ? { description } : {},
69
+ returnType: fn.returnType ?? "any",
70
+ parameters
71
+ };
72
+ });
73
+ const theme = catalog.themeSchema ? serializeA2UISchema(catalog.themeSchema, commonTypes).properties : void 0;
74
+ return {
75
+ catalogId: catalog.id,
76
+ components,
77
+ ...functions.length > 0 ? { functions } : {},
78
+ ...theme ? { theme } : {},
79
+ ...Object.keys(commonTypes).length > 0 ? { "common_types.json": { $defs: commonTypes } } : {}
80
+ };
81
+ }
82
+ /**
83
+ * Build a context string describing the catalog's id and the components it
84
+ * adds beyond the basic catalog.
85
+ *
86
+ * Schemas are serialized as in {@link extractA2UICatalogSchemas}, with the
87
+ * common types they reference listed once after the components.
88
+ *
89
+ * When `options.includeSchema` is `false`, custom components are listed by name
90
+ * only and their JSON schemas are omitted.
91
+ */
92
+ function buildA2UICatalogContextValue(catalog, basicComponentNames, options) {
93
+ const lines = ["Available A2UI catalog:"];
94
+ if (catalog.id === A2UI_BASIC_CATALOG_ID) {
95
+ lines.push(`- ${catalog.id} (basic catalog)`);
96
+ return lines.join("\n");
97
+ }
98
+ const isSuperset = [...basicComponentNames].every((name) => catalog.components.has(name));
99
+ lines.push(`- ${catalog.id}`);
100
+ if (isSuperset) lines.push(" Extends the basic catalog with all standard components plus:");
101
+ else {
102
+ lines.push(" Custom catalog (does NOT include all basic components).");
103
+ lines.push(" Custom components:");
104
+ }
105
+ const commonTypes = Object.create(null);
106
+ for (const [name, component] of catalog.components) {
107
+ if (basicComponentNames.has(name)) continue;
108
+ if (options?.includeSchema === false) {
109
+ lines.push(` - ${name}`);
110
+ continue;
111
+ }
112
+ lines.push(` - ${name}:`);
113
+ lines.push(indented(serializeA2UISchema(component.schema, commonTypes)));
114
+ }
115
+ if (Object.keys(commonTypes).length > 0) {
116
+ lines.push(" Common types referenced above (common_types.json#/$defs):");
117
+ lines.push(indented(commonTypes));
118
+ }
119
+ return lines.join("\n");
120
+ }
121
+ /** JSON for the catalog context value, indented under a list item. */
122
+ function indented(value) {
123
+ return ` ${JSON.stringify(value, null, 2).split("\n").join("\n ")}`;
124
+ }
125
+ /** Raw zod-to-json-schema output per Zod schema, stored as JSON text. */
126
+ const serializedSchemas = /* @__PURE__ */ new WeakMap();
127
+ /**
128
+ * Convert one A2UI Zod schema to JSON Schema 2019-09, inlining reused schemas
129
+ * and resolving `REF:` markers (see {@link extractA2UICatalogSchemas}). The
130
+ * shapes behind `common_types.json` refs are recorded in `commonTypes`; pass
131
+ * the same map for every schema of one payload.
132
+ *
133
+ * The raw conversion is cached per schema object as JSON text, and every call
134
+ * parses a fresh copy. The JSON round-trip, unlike structuredClone, never
135
+ * throws on values such as a function or a Vue reactive proxy in a
136
+ * `.default()`, and yields exactly what the agent receives.
137
+ */
138
+ function serializeA2UISchema(schema, commonTypes = Object.create(null)) {
139
+ const key = typeof schema === "object" && schema !== null ? schema : null;
140
+ let serialized = key ? serializedSchemas.get(key) : void 0;
141
+ if (serialized === void 0) {
142
+ const jsonSchema = (0, zod_to_json_schema.zodToJsonSchema)(schema, {
143
+ target: "jsonSchema2019-09",
144
+ $refStrategy: "none",
145
+ override: (_def, refs, seen, forceResolution) => seen && !forceResolution && seen.path.length < refs.currentPath.length && seen.path.every((part, i) => refs.currentPath[i] === part) ? {} : zod_to_json_schema.ignoreOverride
146
+ });
147
+ delete jsonSchema.$schema;
148
+ serialized = JSON.stringify(jsonSchema);
149
+ if (key) serializedSchemas.set(key, serialized);
150
+ }
151
+ const root = JSON.parse(serialized);
152
+ const marker = parseRefMarker(root.description);
153
+ if (marker) {
154
+ delete root.description;
155
+ if (marker.description) root.description = marker.description;
156
+ }
157
+ return resolveSubschemas(root, commonTypes);
158
+ }
159
+ /** Keywords whose value is a subschema, or an array of subschemas. */
160
+ const SUBSCHEMA_KEYWORDS = [
161
+ "items",
162
+ "additionalItems",
163
+ "additionalProperties",
164
+ "unevaluatedItems",
165
+ "unevaluatedProperties",
166
+ "contains",
167
+ "propertyNames",
168
+ "not",
169
+ "if",
170
+ "then",
171
+ "else",
172
+ "allOf",
173
+ "anyOf",
174
+ "oneOf",
175
+ "prefixItems"
176
+ ];
177
+ /** Keywords whose value maps names to subschemas. */
178
+ const SUBSCHEMA_MAP_KEYWORDS = [
179
+ "properties",
180
+ "patternProperties",
181
+ "dependentSchemas",
182
+ "$defs",
183
+ "definitions"
184
+ ];
185
+ const COMMON_TYPE_REF = /^common_types\.json#\/\$defs\/([^/]+)$/;
186
+ function isObject(value) {
187
+ return typeof value === "object" && value !== null && !Array.isArray(value);
188
+ }
189
+ /**
190
+ * Split a `REF:<ref>|<description>` marker at its first `|`, so a description
191
+ * containing `|` is kept whole. The convention comes from
192
+ * `MessageProcessor.processRefs` in `@a2ui/web_core`.
193
+ */
194
+ function parseRefMarker(description) {
195
+ if (typeof description !== "string" || !description.startsWith("REF:")) return;
196
+ const body = description.slice(4);
197
+ const separator = body.indexOf("|");
198
+ return separator === -1 ? { ref: body } : {
199
+ ref: body.slice(0, separator),
200
+ description: body.slice(separator + 1)
201
+ };
202
+ }
203
+ /**
204
+ * Resolve `REF:` markers in a schema's subschemas, innermost first, so a
205
+ * stored common type refers to the types it contains by bare `$ref` too.
206
+ *
207
+ * Only schema-valued keywords are traversed, so literal values under
208
+ * `default`, `const`, `enum` or `examples` are never rewritten.
209
+ */
210
+ function resolveSubschemas(node, commonTypes) {
211
+ const resolve = (value) => Array.isArray(value) ? value.map(resolve) : isObject(value) ? resolveRefMarker(resolveSubschemas(value, commonTypes), commonTypes) : value;
212
+ const out = { ...node };
213
+ for (const keyword of SUBSCHEMA_KEYWORDS) if (keyword in out) out[keyword] = resolve(out[keyword]);
214
+ for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
215
+ const map = out[keyword];
216
+ if (isObject(map)) out[keyword] = Object.fromEntries(Object.entries(map).map(([name, child]) => [name, resolve(child)]));
217
+ }
218
+ return out;
219
+ }
220
+ /**
221
+ * Turn a node carrying a `REF:` marker into a bare `$ref`, recording the
222
+ * shape it replaced under its `common_types.json` name. A shape that differs
223
+ * from the one already recorded, or a ref outside `common_types.json`, stays
224
+ * inline next to the `$ref`.
225
+ */
226
+ function resolveRefMarker(node, commonTypes) {
227
+ const marker = parseRefMarker(node.description);
228
+ if (!marker) return node;
229
+ const { description: _marker, ...shape } = node;
230
+ const ref = {
231
+ $ref: marker.ref,
232
+ ...marker.description ? { description: marker.description } : {}
233
+ };
234
+ const name = COMMON_TYPE_REF.exec(marker.ref)?.[1];
235
+ if (name !== void 0) {
236
+ const known = commonTypes[name];
237
+ if (known === void 0) {
238
+ commonTypes[name] = shape;
239
+ return ref;
240
+ }
241
+ if (JSON.stringify(known) === JSON.stringify(shape)) return ref;
242
+ }
243
+ return {
244
+ ...ref,
245
+ ...shape
246
+ };
247
+ }
248
+ /**
249
+ * Read a catalog's functions, tolerating catalog-shaped objects whose
250
+ * `functions` is missing, a plain object or an array, and skipping entries
251
+ * without a name or schema.
252
+ */
253
+ function catalogFunctions(functions) {
254
+ if (typeof functions !== "object" || functions === null) return [];
255
+ 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);
256
+ }
257
+
258
+ //#endregion
259
+ exports.A2UI_BASIC_CATALOG_ID = A2UI_BASIC_CATALOG_ID;
260
+ exports.A2UI_SCHEMA_CONTEXT_DESCRIPTION = A2UI_SCHEMA_CONTEXT_DESCRIPTION;
261
+ exports.buildA2UICatalogContextValue = buildA2UICatalogContextValue;
262
+ exports.extractA2UICatalogSchemas = extractA2UICatalogSchemas;
263
+ exports.serializeA2UISchema = serializeA2UISchema;
264
+ //# sourceMappingURL=a2ui-catalog-schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-catalog-schema.cjs","names":["ignoreOverride"],"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;GA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,cAAc,KAAM,QAAO,EAAE;AAOlE,SALE,qBAAqB,MACjB,CAAC,GAAG,UAAU,QAAQ,CAAC,GACvB,MAAM,QAAQ,UAAU,GACtB,YACA,OAAO,OAAO,UAAU,EACjB,QACZ,OACC,OAAO,OAAO,YACd,OAAO,QACP,OAAO,GAAG,SAAS,YACnB,OAAO,GAAG,WAAW,YACrB,GAAG,WAAW,KACjB"}
@@ -0,0 +1,112 @@
1
+ //#region src/a2ui-catalog-schema.d.ts
2
+ /**
3
+ * Context description used to identify the A2UI component schema in
4
+ * RunAgentInput.context. Must match the constant in @ag-ui/a2ui-middleware so
5
+ * the middleware can overwrite a frontend-provided schema with a server-side one.
6
+ */
7
+ declare const A2UI_SCHEMA_CONTEXT_DESCRIPTION = "A2UI Component Schema \u2014 available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.";
8
+ /** Id of the A2UI v0.9 basic catalog. */
9
+ declare const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json";
10
+ type JsonSchema = Record<string, unknown>;
11
+ /**
12
+ * The parts of an `@a2ui/web_core` v0.9 `Catalog` that the serializers read.
13
+ * Typed structurally so this module does not depend on web_core, and so the
14
+ * minimal catalog-shaped objects some apps pass in still work.
15
+ */
16
+ interface A2UICatalogSchemaSource {
17
+ readonly id: string;
18
+ readonly components: ReadonlyMap<string, {
19
+ readonly schema: unknown;
20
+ }>;
21
+ /** A `ReadonlyMap` on a real `Catalog`; anything else is tolerated. */
22
+ readonly functions?: unknown;
23
+ readonly themeSchema?: unknown;
24
+ }
25
+ /** One entry of {@link A2UIInlineCatalogSchema.functions}. */
26
+ interface A2UIFunctionSchema {
27
+ name: string;
28
+ description?: string;
29
+ returnType: string;
30
+ parameters: JsonSchema;
31
+ }
32
+ /**
33
+ * A2UI v0.9 inline catalog, the shape of `InlineCatalog` in
34
+ * `@a2ui/web_core/v0_9`, sent to the agent as the component schema.
35
+ */
36
+ interface A2UIInlineCatalogSchema {
37
+ catalogId: string;
38
+ components: Record<string, JsonSchema>;
39
+ functions?: A2UIFunctionSchema[];
40
+ theme?: Record<string, JsonSchema>;
41
+ /**
42
+ * One copy of each common type the schemas reference, so every
43
+ * `common_types.json#/$defs/<Name>` ref resolves within this payload.
44
+ */
45
+ "common_types.json"?: {
46
+ $defs: A2UICommonTypes;
47
+ };
48
+ }
49
+ /** Common type shapes keyed by their `common_types.json` `$defs` name. */
50
+ type A2UICommonTypes = Record<string, JsonSchema>;
51
+ /**
52
+ * Serialize a catalog's Zod schemas in the A2UI v0.9 inline catalog format.
53
+ *
54
+ * Each component composes `ComponentCommon` with its own properties, matching
55
+ * the flat wire format the agent must produce:
56
+ *
57
+ * { "Column": { "allOf": [
58
+ * { "$ref": "common_types.json#/$defs/ComponentCommon" },
59
+ * { "properties": { "component": {"const":"Column"}, "gap": ..., "children": ... },
60
+ * "required": ["component"] }
61
+ * ]}}
62
+ *
63
+ * This follows `getClientCapabilities` in `@a2ui/web_core` with these
64
+ * deliberate differences:
65
+ *
66
+ * - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which
67
+ * would dangle once properties move under `allOf[1]`.
68
+ * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but
69
+ * the shape it replaced is kept once under
70
+ * `"common_types.json": { "$defs": { <Name>: ... } }`. Every
71
+ * `common_types.json#/$defs/<Name>` ref therefore resolves within the
72
+ * payload, both for agents that only see it as prompt text and for SDKs
73
+ * (such as Google's A2UI SDK used by ADK) that read the `$ref`. Each type is
74
+ * stated once rather than at every use site, which keeps the payload small.
75
+ * A use whose shape differs from the stored one keeps its shape inline next
76
+ * to the `$ref`, so the agent never sees a looser type than the client
77
+ * accepts.
78
+ * - A `REF:` marker on a schema's root only sets its description; replacing
79
+ * the root would drop every property.
80
+ * - A component's root `.describe()` is kept as the component `description`.
81
+ * - Function parameters drop `$schema` and the description already given on
82
+ * the function itself, to keep the prompt small.
83
+ */
84
+ declare function extractA2UICatalogSchemas(catalog: A2UICatalogSchemaSource): A2UIInlineCatalogSchema;
85
+ /**
86
+ * Build a context string describing the catalog's id and the components it
87
+ * adds beyond the basic catalog.
88
+ *
89
+ * Schemas are serialized as in {@link extractA2UICatalogSchemas}, with the
90
+ * common types they reference listed once after the components.
91
+ *
92
+ * When `options.includeSchema` is `false`, custom components are listed by name
93
+ * only and their JSON schemas are omitted.
94
+ */
95
+ declare function buildA2UICatalogContextValue(catalog: A2UICatalogSchemaSource, basicComponentNames: ReadonlySet<string>, options?: {
96
+ includeSchema?: boolean;
97
+ }): string;
98
+ /**
99
+ * Convert one A2UI Zod schema to JSON Schema 2019-09, inlining reused schemas
100
+ * and resolving `REF:` markers (see {@link extractA2UICatalogSchemas}). The
101
+ * shapes behind `common_types.json` refs are recorded in `commonTypes`; pass
102
+ * the same map for every schema of one payload.
103
+ *
104
+ * The raw conversion is cached per schema object as JSON text, and every call
105
+ * parses a fresh copy. The JSON round-trip, unlike structuredClone, never
106
+ * throws on values such as a function or a Vue reactive proxy in a
107
+ * `.default()`, and yields exactly what the agent receives.
108
+ */
109
+ declare function serializeA2UISchema(schema: unknown, commonTypes?: A2UICommonTypes): JsonSchema;
110
+ //#endregion
111
+ export { A2UICatalogSchemaSource, A2UICommonTypes, A2UIFunctionSchema, A2UIInlineCatalogSchema, A2UI_BASIC_CATALOG_ID, A2UI_SCHEMA_CONTEXT_DESCRIPTION, buildA2UICatalogContextValue, extractA2UICatalogSchemas, serializeA2UISchema };
112
+ //# sourceMappingURL=a2ui-catalog-schema.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-catalog-schema.d.cts","names":[],"sources":["../src/a2ui-catalog-schema.ts"],"mappings":";;AAOA;;;;cAAa,+BAAA;AAIb;AAAA,cAAa,qBAAA;AAAA,KAGR,UAAA,GAAa,MAAA;;;AAFyC;;;UAS1C,uBAAA;EAAA,SACN,EAAA;EAAA,SACA,UAAA,EAAY,WAAA;IAAA,SAA+B,MAAA;EAAA;EAApB;EAAA,SAEvB,SAAA;EAAA,SACA,WAAA;AAAA;;UAIM,kBAAA;EACf,IAAA;EACA,WAAA;EACA,UAAA;EACA,UAAA,EAAY,UAAA;AAAA;;;;;UAOG,uBAAA;EACf,SAAA;EACA,UAAA,EAAY,MAAA,SAAe,UAAA;EAC3B,SAAA,GAAY,kBAAA;EACZ,KAAA,GAAQ,MAAA,SAAe,UAAA;EAJR;;;;EASf,mBAAA;IAAwB,KAAA,EAAO,eAAA;EAAA;AAAA;;KAIrB,eAAA,GAAkB,MAAA,SAAe,UAAA;;;;;;;;;;;;;;;;AAA7C;;;;;AAmCA;;;;;;;;;AAmEA;;;;iBAnEgB,yBAAA,CACd,OAAA,EAAS,uBAAA,GACR,uBAAA;;;;;;;;AAwIH;;;iBAvEgB,4BAAA,CACd,OAAA,EAAS,uBAAA,EACT,mBAAA,EAAqB,WAAA,UACrB,OAAA;EAAY,aAAA;AAAA;;;;;;;;;;;;iBAoEE,mBAAA,CACd,MAAA,WACA,WAAA,GAAa,eAAA,GACZ,UAAA"}
@@ -0,0 +1,112 @@
1
+ //#region src/a2ui-catalog-schema.d.ts
2
+ /**
3
+ * Context description used to identify the A2UI component schema in
4
+ * RunAgentInput.context. Must match the constant in @ag-ui/a2ui-middleware so
5
+ * the middleware can overwrite a frontend-provided schema with a server-side one.
6
+ */
7
+ declare const A2UI_SCHEMA_CONTEXT_DESCRIPTION = "A2UI Component Schema \u2014 available components for generating UI surfaces. Use these component names and properties when creating A2UI operations.";
8
+ /** Id of the A2UI v0.9 basic catalog. */
9
+ declare const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json";
10
+ type JsonSchema = Record<string, unknown>;
11
+ /**
12
+ * The parts of an `@a2ui/web_core` v0.9 `Catalog` that the serializers read.
13
+ * Typed structurally so this module does not depend on web_core, and so the
14
+ * minimal catalog-shaped objects some apps pass in still work.
15
+ */
16
+ interface A2UICatalogSchemaSource {
17
+ readonly id: string;
18
+ readonly components: ReadonlyMap<string, {
19
+ readonly schema: unknown;
20
+ }>;
21
+ /** A `ReadonlyMap` on a real `Catalog`; anything else is tolerated. */
22
+ readonly functions?: unknown;
23
+ readonly themeSchema?: unknown;
24
+ }
25
+ /** One entry of {@link A2UIInlineCatalogSchema.functions}. */
26
+ interface A2UIFunctionSchema {
27
+ name: string;
28
+ description?: string;
29
+ returnType: string;
30
+ parameters: JsonSchema;
31
+ }
32
+ /**
33
+ * A2UI v0.9 inline catalog, the shape of `InlineCatalog` in
34
+ * `@a2ui/web_core/v0_9`, sent to the agent as the component schema.
35
+ */
36
+ interface A2UIInlineCatalogSchema {
37
+ catalogId: string;
38
+ components: Record<string, JsonSchema>;
39
+ functions?: A2UIFunctionSchema[];
40
+ theme?: Record<string, JsonSchema>;
41
+ /**
42
+ * One copy of each common type the schemas reference, so every
43
+ * `common_types.json#/$defs/<Name>` ref resolves within this payload.
44
+ */
45
+ "common_types.json"?: {
46
+ $defs: A2UICommonTypes;
47
+ };
48
+ }
49
+ /** Common type shapes keyed by their `common_types.json` `$defs` name. */
50
+ type A2UICommonTypes = Record<string, JsonSchema>;
51
+ /**
52
+ * Serialize a catalog's Zod schemas in the A2UI v0.9 inline catalog format.
53
+ *
54
+ * Each component composes `ComponentCommon` with its own properties, matching
55
+ * the flat wire format the agent must produce:
56
+ *
57
+ * { "Column": { "allOf": [
58
+ * { "$ref": "common_types.json#/$defs/ComponentCommon" },
59
+ * { "properties": { "component": {"const":"Column"}, "gap": ..., "children": ... },
60
+ * "required": ["component"] }
61
+ * ]}}
62
+ *
63
+ * This follows `getClientCapabilities` in `@a2ui/web_core` with these
64
+ * deliberate differences:
65
+ *
66
+ * - Reused Zod schemas are inlined rather than emitted as local `$ref`s, which
67
+ * would dangle once properties move under `allOf[1]`.
68
+ * - A `REF:<ref>|<description>` marker becomes a bare `$ref`, as upstream, but
69
+ * the shape it replaced is kept once under
70
+ * `"common_types.json": { "$defs": { <Name>: ... } }`. Every
71
+ * `common_types.json#/$defs/<Name>` ref therefore resolves within the
72
+ * payload, both for agents that only see it as prompt text and for SDKs
73
+ * (such as Google's A2UI SDK used by ADK) that read the `$ref`. Each type is
74
+ * stated once rather than at every use site, which keeps the payload small.
75
+ * A use whose shape differs from the stored one keeps its shape inline next
76
+ * to the `$ref`, so the agent never sees a looser type than the client
77
+ * accepts.
78
+ * - A `REF:` marker on a schema's root only sets its description; replacing
79
+ * the root would drop every property.
80
+ * - A component's root `.describe()` is kept as the component `description`.
81
+ * - Function parameters drop `$schema` and the description already given on
82
+ * the function itself, to keep the prompt small.
83
+ */
84
+ declare function extractA2UICatalogSchemas(catalog: A2UICatalogSchemaSource): A2UIInlineCatalogSchema;
85
+ /**
86
+ * Build a context string describing the catalog's id and the components it
87
+ * adds beyond the basic catalog.
88
+ *
89
+ * Schemas are serialized as in {@link extractA2UICatalogSchemas}, with the
90
+ * common types they reference listed once after the components.
91
+ *
92
+ * When `options.includeSchema` is `false`, custom components are listed by name
93
+ * only and their JSON schemas are omitted.
94
+ */
95
+ declare function buildA2UICatalogContextValue(catalog: A2UICatalogSchemaSource, basicComponentNames: ReadonlySet<string>, options?: {
96
+ includeSchema?: boolean;
97
+ }): string;
98
+ /**
99
+ * Convert one A2UI Zod schema to JSON Schema 2019-09, inlining reused schemas
100
+ * and resolving `REF:` markers (see {@link extractA2UICatalogSchemas}). The
101
+ * shapes behind `common_types.json` refs are recorded in `commonTypes`; pass
102
+ * the same map for every schema of one payload.
103
+ *
104
+ * The raw conversion is cached per schema object as JSON text, and every call
105
+ * parses a fresh copy. The JSON round-trip, unlike structuredClone, never
106
+ * throws on values such as a function or a Vue reactive proxy in a
107
+ * `.default()`, and yields exactly what the agent receives.
108
+ */
109
+ declare function serializeA2UISchema(schema: unknown, commonTypes?: A2UICommonTypes): JsonSchema;
110
+ //#endregion
111
+ export { A2UICatalogSchemaSource, A2UICommonTypes, A2UIFunctionSchema, A2UIInlineCatalogSchema, A2UI_BASIC_CATALOG_ID, A2UI_SCHEMA_CONTEXT_DESCRIPTION, buildA2UICatalogContextValue, extractA2UICatalogSchemas, serializeA2UISchema };
112
+ //# sourceMappingURL=a2ui-catalog-schema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui-catalog-schema.d.mts","names":[],"sources":["../src/a2ui-catalog-schema.ts"],"mappings":";;AAOA;;;;cAAa,+BAAA;AAIb;AAAA,cAAa,qBAAA;AAAA,KAGR,UAAA,GAAa,MAAA;;;AAFyC;;;UAS1C,uBAAA;EAAA,SACN,EAAA;EAAA,SACA,UAAA,EAAY,WAAA;IAAA,SAA+B,MAAA;EAAA;EAApB;EAAA,SAEvB,SAAA;EAAA,SACA,WAAA;AAAA;;UAIM,kBAAA;EACf,IAAA;EACA,WAAA;EACA,UAAA;EACA,UAAA,EAAY,UAAA;AAAA;;;;;UAOG,uBAAA;EACf,SAAA;EACA,UAAA,EAAY,MAAA,SAAe,UAAA;EAC3B,SAAA,GAAY,kBAAA;EACZ,KAAA,GAAQ,MAAA,SAAe,UAAA;EAJR;;;;EASf,mBAAA;IAAwB,KAAA,EAAO,eAAA;EAAA;AAAA;;KAIrB,eAAA,GAAkB,MAAA,SAAe,UAAA;;;;;;;;;;;;;;;;AAA7C;;;;;AAmCA;;;;;;;;;AAmEA;;;;iBAnEgB,yBAAA,CACd,OAAA,EAAS,uBAAA,GACR,uBAAA;;;;;;;;AAwIH;;;iBAvEgB,4BAAA,CACd,OAAA,EAAS,uBAAA,EACT,mBAAA,EAAqB,WAAA,UACrB,OAAA;EAAY,aAAA;AAAA;;;;;;;;;;;;iBAoEE,mBAAA,CACd,MAAA,WACA,WAAA,GAAa,eAAA,GACZ,UAAA"}