@aestheticfunction/dspack-emit 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,8 +52,8 @@ https://github.com/user-attachments/assets/510a781b-4214-49b3-b997-9cbecdc36961
52
52
  | --- | --- |
53
53
  | `input/shadcn-ui.dspack.json` | Example input: a dspack v0.4 contract from a React+Tailwind system (shadcn/ui). **Pinned to v2.3.0 (8 components) — not current shadcn coverage;** see [`docs/CONTRACT-PIN.md`](docs/CONTRACT-PIN.md). |
54
54
  | `src/` | The transformer: source-agnostic engine + data-only profile + versioned emitter + validator. |
55
- | `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components. |
56
- | `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (no external `$ref`, versioned `catalogId`). |
55
+ | `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components (`settings-card.v1_0.surface.json`: the same surface in 1.0 message form). |
56
+ | `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (versioned `catalogId`). The 0.9.1 catalog is self-contained; the 1.0 catalog references the pinned `common_types.json`, as the 1.0 specification requires. |
57
57
  | `out/validation-report.*` | Validation + fidelity reports (Markdown + JSON). |
58
58
  | `docs/MAPPING.md` | Per-field fidelity narrative and the deliberate casualties. |
59
59
  | `demo/` | Standalone Vite + React 19 app rendering the surface via `@a2ui/react`. |
@@ -120,15 +120,18 @@ the repo-relative sample-surface default is skipped (gate A3 then covers
120
120
 
121
121
  ### Versioned emitter (`--a2ui-version 0.9.1 | 1.0`)
122
122
 
123
- The mapper targets and validates the **v1.0** catalog schema as the primary line, and
124
- also emits **v0.9.1** for the renderer demo (maintained React renderers are stable on
125
- v0.9.1). Confirmed against the checked-in fixtures, the only catalog-facing delta is:
123
+ Both versions are emitted from the same mapping result.
126
124
 
127
- - **v0.9.1** → `$defs.theme` (carries `primaryColor`, `#rrggbb`).
128
- - **v1.0** → `$defs.surfaceProperties` + a top-level `instructions`.
125
+ - **v0.9.1**, for the renderer demo and today's consumers: self-contained, with every shared definition inlined and
126
+ `$defs.theme` carrying `primaryColor` (`#rrggbb`).
127
+ - **v1.0**, conformant with the pinned final specification (P1a): `protocolVersion: "1.0"`, flat components,
128
+ `common_types.json` references, `anyFunction`, design tokens in `metadata.extensions`, and ARIA-named properties
129
+ carried by the envelope's `@accessibility`. See [docs/A2UI-1.0-CATALOG.md](docs/A2UI-1.0-CATALOG.md) for each rule,
130
+ the mapping, the independent validator results and the limitations. A consumer that compiles a 1.0 catalog itself
131
+ registers `catalogCompanionSchemas(catalog)` beside it.
129
132
 
130
- (See `docs/MAPPING.md` for the full confirmation, including the dropped
131
- `CatalogComponentCommon` def in v1.0, which washes out because we inline all defs.)
133
+ What "1.0" covers today: the **catalog** (validated against the official specification schema). Surfaces are still
134
+ emitted as 0.9.1 **messages**, and nothing here **renders** 1.0, so this is not complete A2UI 1.0 support.
132
135
 
133
136
  ## Validation (the hard gate)
134
137
 
@@ -136,11 +139,14 @@ v0.9.1). Confirmed against the checked-in fixtures, the only catalog-facing delt
136
139
  (draft 2020-12, `strict:false`, `ajv-formats` — the same toolchain A2UI itself uses):
137
140
 
138
141
  1. **schema-compile + no-external-ref** — ajv compiles the catalog *as a schema*;
139
- fails on any unresolved `$ref`, proving it is a valid, fully self-contained schema.
142
+ fails on any unresolved `$ref`, proving it is a valid, fully self-contained schema
143
+ (for 1.0: every external reference is one of the specification's listed `common_types.json` types).
140
144
  2. **catalog-shape** — validates against a version-specific catalog-shape meta-schema
141
- (`src/validate/meta/`), the check that makes v0.9.1 vs v1.0 conformance distinct.
145
+ (`src/validate/meta/`), the check that makes v0.9.1 vs v1.0 conformance distinct. For 1.0
146
+ this is the official `catalog_definition.json`, plus dspack's invariants.
142
147
  3. **instance** — every component instance in the sample surface validates against the
143
- catalog's own `#/$defs/anyComponent`.
148
+ catalog's own `#/$defs/anyComponent` (for 1.0: as the envelope composes it, `ComponentCommon`
149
+ with the catalog component, closed; instances must therefore be in 1.0 message form).
144
150
 
145
151
  The CLI exits non-zero if any gate fails. Both emitted versions currently pass all
146
152
  three. The instance gate is proven non-vacuous in the test suite (it rejects a
package/dist/cli.js CHANGED
@@ -97,9 +97,11 @@ function parseArgs(argv) {
97
97
  in: input,
98
98
  version: (version ?? "0.9.1"),
99
99
  out: m.get("out") ?? "out",
100
- // The sample-surface default is a repo-relative fixture; external callers
100
+ // The sample-surface default is a repo-relative fixture, one per A2UI
101
+ // version (the 1.0 sample is in 1.0 message form); external callers
101
102
  // (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
102
- surface: m.get("surface") ?? (profile ? undefined : "surface/settings-card.surface.json"),
103
+ surface: m.get("surface") ??
104
+ (profile ? undefined : version === "1.0" ? "surface/settings-card.v1_0.surface.json" : "surface/settings-card.surface.json"),
103
105
  profile,
104
106
  emitSurface: m.get("emit-surface"),
105
107
  strictCoverage: m.get("strict-coverage") === "true",
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export { ProfileContractError, type ProfileContractIssue } from "./transform/val
12
12
  export { ProfileParseError, type ParseIssue, type SurfaceV2 } from "./transform/parse-v2.js";
13
13
  export type { SurfaceFidelityEntry } from "./types.js";
14
14
  export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
15
- export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
15
+ export { validateCatalog, extractInstances, catalogCompanionSchemas, type ValidationReport, type GateResult } from "./validate/ajv.js";
16
16
  export { emitSurface, slug, EmitSurfaceError, type EmitSurfaceResult, type EmitSurfaceOptions, } from "./targets/a2ui/surface.js";
17
17
  export { emitJsonRenderSpec, validateSpecAgainstModel, EmitJsonRenderError, type EmitJsonRenderResult, type EmitJsonRenderOptions, type JsonRenderSpec, type JsonRenderElement, type SpecFinding, } from "./targets/json-render/emit.js";
18
18
  export { generateJsonRenderModules, type JsonRenderModules } from "./targets/json-render/codegen.js";
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export { loadProfile, profileSchema, profileSchemaV2, ProfileLoadError } from ".
11
11
  export { ProfileContractError } from "./transform/validate-v2.js";
12
12
  export { ProfileParseError } from "./transform/parse-v2.js";
13
13
  export { scaffoldProfile } from "./transform/scaffold.js";
14
- export { validateCatalog, extractInstances } from "./validate/ajv.js";
14
+ export { validateCatalog, extractInstances, catalogCompanionSchemas } from "./validate/ajv.js";
15
15
  export { emitSurface, slug, EmitSurfaceError, } from "./targets/a2ui/surface.js";
16
16
  export { emitJsonRenderSpec, validateSpecAgainstModel, EmitJsonRenderError, } from "./targets/json-render/emit.js";
17
17
  export { generateJsonRenderModules } from "./targets/json-render/codegen.js";
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The A2UI 1.0 catalog, built from the same mapping result as 0.9.1. Only the differences the 1.0 specification
3
+ * requires live here, each against the pinned upstream (fixtures/a2ui/PIN.md; specification/v1_0/docs/a2ui_protocol.md,
4
+ * "Catalog Schema Rules and Conventions"):
5
+ *
6
+ * - `protocolVersion: "1.0"` (required for catalogs targeting 1.0 and beyond).
7
+ * - Standard types are referenced as `common_types.json#/$defs/<Type>`, never copied into the catalog, and only the
8
+ * types the specification lists may be referenced (rule 3). The 0.9.1 catalog inlines its own copies; 1.0 must not.
9
+ * - Components are flat. `ComponentCommon` is composed by the envelope (agent_to_renderer.json `Component`), so it is
10
+ * not wrapped in per component, and the envelope, not the component, is where `unevaluatedProperties: false` holds
11
+ * (rule 5). A trait such as `Checkable` stays, as in upstream's basic catalog.
12
+ * - `$defs` holds `anyComponent`, `anyFunction` and leaf definitions only (rules 1 and 2). With no functions declared,
13
+ * `anyFunction` is `{"not": {}}`, which matches no call: the form upstream's own function-less 1.0 catalog uses
14
+ * (catalogs/vegachart/v1/catalog.json).
15
+ * - Functions are call-validation schemas: `properties["@call"].const`, optional `args`, `returnType` (rule 6). As with
16
+ * components, the envelope (`FunctionCall`, composing `FunctionCommon`) closes the object, not the function schema.
17
+ * - There is no `surfaceProperties`. Design tokens are catalog-level metadata, `metadata.extensions.dspack_tokens`
18
+ * (rule 7; extension names are UAX #31 identifiers with a product prefix).
19
+ * - Every component, function and property name is a UAX #31 identifier. A design-system property whose name is an
20
+ * ARIA attribute maps onto the envelope's `@accessibility` instead of being renamed, so the catalog never declares a
21
+ * second channel for the same accessible name ("Catalog-Agnostic Accessibility Requirements").
22
+ *
23
+ * Anything this module cannot represent faithfully is refused with a stated reason rather than emitted approximately.
24
+ */
25
+ import type { A2uiCatalog, FidelityEntry } from "../types.js";
26
+ import type { MappingResult } from "./mapping.js";
27
+ import type { Profile } from "./profiles.js";
28
+ /** The standard types a 1.0 catalog may reference in common_types.json (rule 3), in the specification's order. */
29
+ export declare const COMMON_TYPES_V1_0: readonly ["ComponentId", "Child", "ChildList", "DynamicString", "DynamicNumber", "DynamicBoolean", "DynamicStringList", "DynamicValue", "AccessibilityAttributes", "CheckRule", "Checkable", "Action", "DataBinding", "FunctionCall"];
30
+ /**
31
+ * Design-system properties named after an ARIA attribute, and the `@accessibility` attribute that carries the same
32
+ * meaning on a 1.0 component instance (common_types.json AccessibilityAttributes: label, description, live, hidden).
33
+ */
34
+ export declare const ARIA_TO_ACCESSIBILITY: Readonly<Record<string, "label" | "description" | "live" | "hidden">>;
35
+ /** The catalog-level extension that carries the design tokens (a product-prefixed UAX #31 name). */
36
+ export declare const TOKEN_EXTENSION = "dspack_tokens";
37
+ /**
38
+ * The component-level extension that records which design-system properties the envelope now carries:
39
+ * `{ properties: { "<aria-name>": { carriedBy: "@accessibility.<attribute>", schema: <the property's own schema> } } }`.
40
+ */
41
+ export declare const ACCESSIBILITY_EXTENSION = "dspack_accessibility";
42
+ /** The 1.0 catalog. Throws, with the reason, when the mapping holds something 1.0 cannot represent. */
43
+ export declare function emitCatalogV1_0(result: MappingResult, profile: Profile, id: string): A2uiCatalog;
44
+ /** The mapping's fidelity entries as they read for the 1.0 catalog: where tokens and ARIA properties actually go. */
45
+ export declare function fidelityV1_0(result: MappingResult): FidelityEntry[];
@@ -0,0 +1,190 @@
1
+ /** The standard types a 1.0 catalog may reference in common_types.json (rule 3), in the specification's order. */
2
+ export const COMMON_TYPES_V1_0 = [
3
+ "ComponentId",
4
+ "Child",
5
+ "ChildList",
6
+ "DynamicString",
7
+ "DynamicNumber",
8
+ "DynamicBoolean",
9
+ "DynamicStringList",
10
+ "DynamicValue",
11
+ "AccessibilityAttributes",
12
+ "CheckRule",
13
+ "Checkable",
14
+ "Action",
15
+ "DataBinding",
16
+ "FunctionCall",
17
+ ];
18
+ const COMMON = new Set(COMMON_TYPES_V1_0);
19
+ /**
20
+ * Design-system properties named after an ARIA attribute, and the `@accessibility` attribute that carries the same
21
+ * meaning on a 1.0 component instance (common_types.json AccessibilityAttributes: label, description, live, hidden).
22
+ */
23
+ export const ARIA_TO_ACCESSIBILITY = {
24
+ "aria-label": "label",
25
+ "aria-description": "description",
26
+ "aria-live": "live",
27
+ "aria-hidden": "hidden",
28
+ };
29
+ /** The catalog-level extension that carries the design tokens (a product-prefixed UAX #31 name). */
30
+ export const TOKEN_EXTENSION = "dspack_tokens";
31
+ /**
32
+ * The component-level extension that records which design-system properties the envelope now carries:
33
+ * `{ properties: { "<aria-name>": { carriedBy: "@accessibility.<attribute>", schema: <the property's own schema> } } }`.
34
+ */
35
+ export const ACCESSIBILITY_EXTENSION = "dspack_accessibility";
36
+ /** UAX #31 (`^[\p{XID_Start}_][\p{XID_Continue}]*$`), the rule for every catalog entity name in 1.0. */
37
+ const IDENTIFIER = /^[\p{XID_Start}_][\p{XID_Continue}]*$/u;
38
+ class V1Refusal extends Error {
39
+ }
40
+ /** Re-target a schema's standard-type references at common_types.json; refuse any other #/$defs reference. */
41
+ function retarget(node, at) {
42
+ if (Array.isArray(node))
43
+ return node.map((n, i) => retarget(n, `${at}/${i}`));
44
+ if (!node || typeof node !== "object")
45
+ return node;
46
+ const out = {};
47
+ for (const [k, v] of Object.entries(node)) {
48
+ if (k === "$ref" && typeof v === "string" && v.startsWith("#/$defs/")) {
49
+ const type = v.slice("#/$defs/".length);
50
+ if (!COMMON.has(type)) {
51
+ throw new V1Refusal(`${at}: '${v}' has no A2UI 1.0 counterpart in common_types.json (allowed: ${COMMON_TYPES_V1_0.join(", ")})`);
52
+ }
53
+ out[k] = `common_types.json#/$defs/${type}`;
54
+ }
55
+ else {
56
+ out[k] = retarget(v, `${at}/${k}`);
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+ function component(name, emitted) {
62
+ const parts = (emitted.allOf ?? []);
63
+ const own = parts.find((p) => !("$ref" in p));
64
+ if (!own)
65
+ throw new V1Refusal(`components.${name}: no component schema to emit`);
66
+ const traits = parts
67
+ .filter((p) => "$ref" in p)
68
+ .map((p) => String(p.$ref).slice("#/$defs/".length))
69
+ .filter((t) => t !== "ComponentCommon"); // composed by the envelope (rule 5)
70
+ const schema = retarget(own, `components.${name}`);
71
+ const properties = (schema.properties ?? {});
72
+ const required = (schema.required ?? []).slice();
73
+ const carried = {};
74
+ for (const prop of Object.keys(properties)) {
75
+ const attribute = ARIA_TO_ACCESSIBILITY[prop];
76
+ if (attribute) {
77
+ if (required.includes(prop)) {
78
+ throw new V1Refusal(`components.${name}.${prop}: a required ARIA property cannot move to the optional @accessibility.${attribute}`);
79
+ }
80
+ // The design system's own guidance for the property (its description, a default such as "Loading", its source)
81
+ // stays in the catalog beside the mapping, so an agent reading the 1.0 catalog still learns when and how to set it.
82
+ carried[prop] = { carriedBy: `@accessibility.${attribute}`, schema: properties[prop] };
83
+ delete properties[prop];
84
+ }
85
+ else if (!IDENTIFIER.test(prop)) {
86
+ throw new V1Refusal(`components.${name}.${prop}: not a UAX #31 identifier, and no 1.0 mapping is defined for it`);
87
+ }
88
+ }
89
+ const flat = { ...schema, properties };
90
+ if (Object.keys(carried).length > 0) {
91
+ flat.metadata = { extensions: { [ACCESSIBILITY_EXTENSION]: { properties: carried } } };
92
+ }
93
+ if (traits.length === 0)
94
+ return flat;
95
+ // A trait keeps upstream's basic-catalog form: { type, allOf: [trait, component] }.
96
+ const { metadata, ...body } = flat;
97
+ return {
98
+ type: "object",
99
+ allOf: [...traits.map((t) => ({ $ref: retarget({ $ref: `#/$defs/${t}` }, `components.${name}`).$ref })), body],
100
+ ...(metadata ? { metadata } : {}),
101
+ };
102
+ }
103
+ function functions(profile) {
104
+ const declared = profile.functions;
105
+ const names = declared ? Object.keys(declared).sort() : [];
106
+ if (names.length === 0)
107
+ return { anyFunction: { not: {} } };
108
+ const section = {};
109
+ for (const name of names) {
110
+ if (!IDENTIFIER.test(name))
111
+ throw new V1Refusal(`functions.${name}: not a UAX #31 identifier`);
112
+ const fn = declared[name];
113
+ const args = fn.args ? retarget(fn.args, `functions.${name}.args`) : undefined;
114
+ const requiresArgs = Array.isArray(fn.args?.required) && (fn.args.required.length > 0);
115
+ section[name] = {
116
+ type: "object",
117
+ description: fn.description,
118
+ returnType: fn.returns,
119
+ properties: { "@call": { const: name }, ...(args ? { args } : {}) },
120
+ required: requiresArgs ? ["@call", "args"] : ["@call"],
121
+ // No unevaluatedProperties here: the FunctionCall envelope (common_types.json) composes FunctionCommon with this
122
+ // schema and closes the object itself, as upstream's basic catalog relies on.
123
+ };
124
+ }
125
+ return { section, anyFunction: { oneOf: names.map((n) => ({ $ref: `#/functions/${n}` })) } };
126
+ }
127
+ /** The 1.0 catalog. Throws, with the reason, when the mapping holds something 1.0 cannot represent. */
128
+ export function emitCatalogV1_0(result, profile, id) {
129
+ try {
130
+ const components = {};
131
+ for (const name of result.componentOrder) {
132
+ if (!IDENTIFIER.test(name))
133
+ throw new V1Refusal(`components.${name}: not a UAX #31 identifier`);
134
+ if (name === "Surface")
135
+ throw new V1Refusal("components.Surface: the name is reserved by the protocol");
136
+ components[name] = component(name, result.components[name]);
137
+ }
138
+ const fns = functions(profile);
139
+ const tokens = {
140
+ ...(result.primaryColorHex ? { primaryColor: { value: result.primaryColorHex, source: result.primaryColorSource } } : {}),
141
+ palette: result.tokenExtension["x-dspack-tokens"] ?? {},
142
+ };
143
+ return {
144
+ $schema: "https://json-schema.org/draft/2020-12/schema",
145
+ $id: id,
146
+ protocolVersion: "1.0",
147
+ title: profile.catalogTitle,
148
+ description: profile.catalogDescription,
149
+ catalogId: id,
150
+ ...(profile.instructions !== undefined ? { instructions: profile.instructions } : {}),
151
+ metadata: { extensions: { [TOKEN_EXTENSION]: tokens } },
152
+ components,
153
+ ...(fns.section ? { functions: fns.section } : {}),
154
+ $defs: {
155
+ anyComponent: {
156
+ oneOf: result.componentOrder.map((n) => ({ $ref: `#/components/${n}` })),
157
+ discriminator: { propertyName: "component" },
158
+ },
159
+ anyFunction: fns.anyFunction,
160
+ },
161
+ };
162
+ }
163
+ catch (e) {
164
+ if (e instanceof V1Refusal)
165
+ throw new Error(`A2UI 1.0 catalog refused: ${e.message}`);
166
+ throw e;
167
+ }
168
+ }
169
+ /** The mapping's fidelity entries as they read for the 1.0 catalog: where tokens and ARIA properties actually go. */
170
+ export function fidelityV1_0(result) {
171
+ const out = [];
172
+ for (const f of result.fidelity) {
173
+ if (/theme|surfaceProperties/.test(f.target)) {
174
+ out.push({ ...f, target: `metadata.extensions.${TOKEN_EXTENSION}`, note: f.note.replace(/theme\.primaryColor's #rrggbb pattern/, "the token extension's primaryColor").replace("(additionalProperties allows it)", "(a catalog-level metadata extension)") });
175
+ continue;
176
+ }
177
+ const aria = /^components\.([^.]+)\.properties\.(.+)$/.exec(f.target);
178
+ if (aria && ARIA_TO_ACCESSIBILITY[aria[2]]) {
179
+ out.push({
180
+ ...f,
181
+ target: `components.${aria[1]} instance @accessibility.${ARIA_TO_ACCESSIBILITY[aria[2]]}`,
182
+ class: "synthesis-defaults",
183
+ note: `In A2UI 1.0 the envelope's @accessibility.${ARIA_TO_ACCESSIBILITY[aria[2]]} carries '${aria[2]}' (an ARIA attribute name is not a UAX #31 identifier). The catalog keeps the mapping and the property's own guidance in metadata.extensions.${ACCESSIBILITY_EXTENSION}.`,
184
+ });
185
+ continue;
186
+ }
187
+ out.push(f);
188
+ }
189
+ return out;
190
+ }
@@ -1,13 +1,10 @@
1
1
  /**
2
- * Versioned catalog emitter. The two supported A2UI versions differ only in:
3
- * - v0.9.1: a `$defs.theme` object (carries `primaryColor`, #rrggbb).
4
- * - v1.0: a `$defs.surfaceProperties` object + a top-level `instructions`.
5
- * Everything else (components, inlined `$defs`, `anyComponent`) is identical.
6
- *
7
- * The theme / surfaceProperties shapes are copied from the checked-in fixtures
8
- * (fixtures/a2ui/basic-catalog.{v0_9_1,v1_0}.json) and confirmed in pre-flight.
9
- * We additionally carry the resolved design tokens as a documented extension
10
- * (`additionalProperties: true` on both shapes permits it).
2
+ * Versioned catalog emitter. This module writes the A2UI 0.9.1 catalog, whose
3
+ * `$defs.theme` shape is copied from the checked-in fixture
4
+ * (fixtures/a2ui/basic-catalog.v0_9_1.json); the resolved design tokens ride
5
+ * along as a documented extension (`additionalProperties: true` permits it).
6
+ * The A2UI 1.0 catalog follows different rules and is built from the same
7
+ * mapping result by emit-v1_0.ts.
11
8
  */
12
9
  import type { A2uiCatalog, A2uiVersion } from "../types.js";
13
10
  import type { MappingResult } from "./mapping.js";
@@ -1,4 +1,5 @@
1
1
  import { INLINED_DEFS } from "./inline-defs.js";
2
+ import { emitCatalogV1_0 } from "./emit-v1_0.js";
2
3
  /**
3
4
  * The catalog's function surface, from the profile's declared FunctionPlans:
4
5
  * a documentation section, the name enum for FunctionCall.call, and the
@@ -43,6 +44,9 @@ const VER_SEGMENT = {
43
44
  export function emitCatalog(result, version, profile) {
44
45
  const seg = VER_SEGMENT[version];
45
46
  const id = `${profile.catalogIdBase}/${seg}/catalog.json`;
47
+ // A2UI 1.0 has its own catalog rules (emit-v1_0.ts); everything below is the 0.9.1 catalog, unchanged.
48
+ if (version === "1.0")
49
+ return emitCatalogV1_0(result, profile, id);
46
50
  const anyComponent = {
47
51
  oneOf: result.componentOrder.map((n) => ({ $ref: `#/components/${n}` })),
48
52
  discriminator: { propertyName: "component" },
@@ -71,12 +75,7 @@ export function emitCatalog(result, version, profile) {
71
75
  // match one declared function's branch (name AND args shape together).
72
76
  fc.oneOf = [{ $ref: "#/$defs/anyFunction" }];
73
77
  }
74
- if (version === "0.9.1") {
75
- $defs.theme = themeDef(result);
76
- }
77
- else {
78
- $defs.surfaceProperties = surfacePropertiesDef(result);
79
- }
78
+ $defs.theme = themeDef(result);
80
79
  const catalog = {
81
80
  $schema: "https://json-schema.org/draft/2020-12/schema",
82
81
  $id: id,
@@ -87,20 +86,6 @@ export function emitCatalog(result, version, profile) {
87
86
  ...(functions ? { functions: functions.section } : {}),
88
87
  $defs,
89
88
  };
90
- if (version === "1.0") {
91
- // Insert `instructions` right after description, mirroring the v1.0 fixture order.
92
- return {
93
- $schema: catalog.$schema,
94
- $id: catalog.$id,
95
- title: catalog.title,
96
- description: catalog.description,
97
- instructions: profile.instructions,
98
- catalogId: catalog.catalogId,
99
- components: catalog.components,
100
- ...(catalog.functions ? { functions: catalog.functions } : {}),
101
- $defs: catalog.$defs,
102
- };
103
- }
104
89
  return catalog;
105
90
  }
106
91
  /** v0.9.1 — shape from fixtures/a2ui/basic-catalog.v0_9_1.json#/$defs/theme. */
@@ -133,27 +118,3 @@ function themeDef(result) {
133
118
  ...result.tokenExtension,
134
119
  };
135
120
  }
136
- /** v1.0 — shape from fixtures/a2ui/basic-catalog.v1_0.json#/$defs/surfaceProperties. */
137
- function surfacePropertiesDef(result) {
138
- const def = {
139
- type: "object",
140
- properties: {
141
- iconUrl: {
142
- type: "string",
143
- format: "uri",
144
- description: "A URL for an image that identifies the agent or tool associated with the surface.",
145
- },
146
- agentDisplayName: {
147
- type: "string",
148
- description: "Text displayed next to the surface to identify the agent or tool that created it.",
149
- },
150
- },
151
- additionalProperties: true,
152
- ...result.tokenExtension,
153
- };
154
- // v1.0 basic surfaceProperties has no primaryColor field; carry it as an extension.
155
- if (result.primaryColorHex) {
156
- def["x-dspack-primaryColor"] = { value: result.primaryColorHex, source: result.primaryColorSource };
157
- }
158
- return def;
159
- }
@@ -2,6 +2,7 @@ import { shadcnProfile } from "./profiles.js";
2
2
  import { mapDspack } from "./mapping.js";
3
3
  import { validateProfileAgainstContract } from "./validate-v2.js";
4
4
  import { emitCatalog } from "./emit.js";
5
+ import { fidelityV1_0 } from "./emit-v1_0.js";
5
6
  import { buildReport } from "./report.js";
6
7
  import { validateCatalog } from "../validate/ajv.js";
7
8
  export function transform(doc, version, surface, profile = shadcnProfile) {
@@ -16,7 +17,8 @@ export function transform(doc, version, surface, profile = shadcnProfile) {
16
17
  const mapping = mapDspack(doc, profile);
17
18
  const catalog = emitCatalog(mapping, version, profile);
18
19
  const validation = validateCatalog(catalog, version, surface);
19
- const report = buildReport(version, mapping, validation);
20
+ // The 1.0 report says where tokens and ARIA properties go in a 1.0 catalog; the 0.9.1 report is unchanged.
21
+ const report = buildReport(version, version === "1.0" ? { ...mapping, fidelity: fidelityV1_0(mapping) } : mapping, validation);
20
22
  return { catalog, mapping, validation, report };
21
23
  }
22
24
  /**
package/dist/types.d.ts CHANGED
@@ -78,7 +78,11 @@ export interface A2uiCatalog extends Json {
78
78
  title: string;
79
79
  description: string;
80
80
  catalogId: string;
81
+ /** A2UI 1.0 only: the specification version the catalog targets. Never written for 0.9.1. */
82
+ protocolVersion?: string;
81
83
  instructions?: string;
84
+ /** A2UI 1.0 only: catalog-level metadata (`metadata.extensions`). Never written for 0.9.1. */
85
+ metadata?: Json;
82
86
  components: Record<string, Json>;
83
87
  functions?: Record<string, Json>;
84
88
  $defs: Record<string, Json>;
@@ -29,6 +29,13 @@ export interface ValidationReport {
29
29
  pass: boolean;
30
30
  gates: GateResult[];
31
31
  }
32
+ /**
33
+ * The schemas a consumer must register beside a catalog before compiling it with its own JSON Schema validator.
34
+ * A 0.9.1 catalog is self-contained: none. A 1.0 catalog references the standard types as `common_types.json#/$defs/…`
35
+ * (specification rule 3), so it needs the pinned common_types at the URL that reference resolves to; the specification
36
+ * forbids fetching it. For example, with ajv: `for (const s of catalogCompanionSchemas(catalog)) ajv.addSchema(s)`.
37
+ */
38
+ export declare function catalogCompanionSchemas(catalog: A2uiCatalog): Json[];
32
39
  /** Pull every component instance (object with string `component` + `id`) from a surface. */
33
40
  export declare function extractInstances(surface: unknown, acc?: Json[]): Json[];
34
41
  export declare function validateCatalog(catalog: A2uiCatalog, version: A2uiVersion, surface?: unknown): ValidationReport;
@@ -20,6 +20,8 @@
20
20
  import Ajv2020 from "ajv/dist/2020.js";
21
21
  import addFormats from "ajv-formats";
22
22
  import { catalogMetaSchemas } from "./meta/catalog-meta.js";
23
+ import { catalogDefinitionV1_0, commonTypesV1_0 } from "./meta/a2ui-v1_0.js";
24
+ import { COMMON_TYPES_V1_0 } from "../transform/emit-v1_0.js";
23
25
  function newAjv() {
24
26
  const ajv = new Ajv2020({ strict: false, allErrors: true, validateFormats: true });
25
27
  addFormats(ajv);
@@ -41,6 +43,32 @@ function externalRefs(node, acc = []) {
41
43
  }
42
44
  return acc;
43
45
  }
46
+ /**
47
+ * A2UI 1.0: the one external reference a catalog may make is to a listed standard type in common_types.json, written
48
+ * relative (`common_types.json#/$defs/<Type>`); anything else makes the catalog invalid (specification rule 3).
49
+ */
50
+ const COMMON_REF = /^common_types\.json#\/\$defs\/([A-Za-z]+)$/;
51
+ function allowedV1_0Ref(ref) {
52
+ const m = COMMON_REF.exec(ref);
53
+ return !!m && COMMON_TYPES_V1_0.includes(m[1]);
54
+ }
55
+ /**
56
+ * The vendored 1.0 common_types, registered where a catalog's relative `common_types.json` reference resolves (beside
57
+ * the catalog's own $id). Its `catalog.json#/$defs/anyFunction` then resolves to that same catalog, offline: the
58
+ * specification forbids fetching either over the network.
59
+ */
60
+ function commonTypesBeside(catalogId) {
61
+ return { ...structuredClone(commonTypesV1_0), $id: new URL("common_types.json", catalogId).href };
62
+ }
63
+ /**
64
+ * The schemas a consumer must register beside a catalog before compiling it with its own JSON Schema validator.
65
+ * A 0.9.1 catalog is self-contained: none. A 1.0 catalog references the standard types as `common_types.json#/$defs/…`
66
+ * (specification rule 3), so it needs the pinned common_types at the URL that reference resolves to; the specification
67
+ * forbids fetching it. For example, with ajv: `for (const s of catalogCompanionSchemas(catalog)) ajv.addSchema(s)`.
68
+ */
69
+ export function catalogCompanionSchemas(catalog) {
70
+ return catalog.protocolVersion === "1.0" ? [commonTypesBeside(catalog.$id)] : [];
71
+ }
44
72
  /**
45
73
  * Collect every INTERNAL `$ref` that does not resolve inside the catalog
46
74
  * document, with the JSON path of the offending `$ref` keyword.
@@ -113,13 +141,18 @@ export function extractInstances(surface, acc = []) {
113
141
  }
114
142
  export function validateCatalog(catalog, version, surface) {
115
143
  const gates = [];
116
- // Gate 1 — schema compile + no external $ref + every internal $ref resolves.
117
- const exts = externalRefs(catalog);
144
+ // Gate 1 — schema compile + no external $ref + every internal $ref resolves. In 1.0 the listed standard types in
145
+ // common_types.json are the one permitted external target, resolved against the vendored copy.
146
+ const v1 = version === "1.0";
147
+ const exts = externalRefs(catalog).filter((r) => !(v1 && allowedV1_0Ref(r)));
118
148
  const dangling = danglingInternalRefs(catalog);
119
149
  let compiled = false;
120
150
  let compileErr = "";
121
151
  try {
122
- newAjv().compile(catalog);
152
+ const ajv = newAjv();
153
+ if (v1)
154
+ ajv.addSchema(commonTypesBeside(catalog.$id));
155
+ ajv.compile(catalog);
123
156
  compiled = true;
124
157
  }
125
158
  catch (e) {
@@ -130,7 +163,9 @@ export function validateCatalog(catalog, version, surface) {
130
163
  name: "schema-compile + no-external-ref",
131
164
  pass: selfContained,
132
165
  detail: selfContained
133
- ? "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal and resolves."
166
+ ? v1
167
+ ? "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal or a listed common_types.json type, and resolves."
168
+ : "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal and resolves."
134
169
  : !compiled
135
170
  ? `ajv failed to compile the catalog as a schema: ${compileErr}`
136
171
  : exts.length
@@ -138,17 +173,32 @@ export function validateCatalog(catalog, version, surface) {
138
173
  : `Catalog is not self-contained: ${dangling.length} internal $ref(s) do not resolve.`,
139
174
  errors: exts.length ? [...new Set(exts)] : dangling.length ? dangling : undefined,
140
175
  });
141
- // Gate 2 — catalog shape.
176
+ // Gate 2 — catalog shape. For 1.0 that is the official catalog definition (vendored, pinned) as well as dspack's own
177
+ // invariants; for 0.9.1, the derived meta-schema as before.
142
178
  const meta = catalogMetaSchemas[version];
143
179
  const validateShape = newAjv().compile(meta);
144
- const shapeOk = validateShape(catalog);
180
+ let shapeOk = validateShape(catalog);
181
+ const shapeErrors = shapeOk ? [] : (validateShape.errors ?? []).map(fmtErr);
182
+ if (v1) {
183
+ const official = newAjv();
184
+ official.addSchema(commonTypesV1_0);
185
+ const validateOfficial = official.compile(catalogDefinitionV1_0);
186
+ if (!validateOfficial(catalog)) {
187
+ shapeOk = false;
188
+ shapeErrors.push(...(validateOfficial.errors ?? []).map((e) => `catalog_definition: ${fmtErr(e)}`));
189
+ }
190
+ }
145
191
  gates.push({
146
192
  name: "catalog-shape",
147
193
  pass: shapeOk,
148
194
  detail: shapeOk
149
- ? `Catalog satisfies the A2UI v${version} catalog-shape meta-schema.`
150
- : `Catalog violates the v${version} catalog-shape meta-schema.`,
151
- errors: shapeOk ? undefined : (validateShape.errors ?? []).map(fmtErr),
195
+ ? v1
196
+ ? "Catalog satisfies the official A2UI v1.0 catalog definition and dspack's v1.0 invariants."
197
+ : `Catalog satisfies the A2UI v${version} catalog-shape meta-schema.`
198
+ : v1
199
+ ? "Catalog violates the official A2UI v1.0 catalog definition or dspack's v1.0 invariants."
200
+ : `Catalog violates the v${version} catalog-shape meta-schema.`,
201
+ errors: shapeOk ? undefined : shapeErrors,
152
202
  });
153
203
  // Gate 3 — instances (only if the catalog is usable and a surface was supplied).
154
204
  if (surface !== undefined) {
@@ -169,6 +219,9 @@ export function validateCatalog(catalog, version, surface) {
169
219
  let instances = [];
170
220
  try {
171
221
  const ajv = newAjv();
222
+ const commonTypes = v1 ? commonTypesBeside(catalog.$id) : undefined;
223
+ if (commonTypes)
224
+ ajv.addSchema(commonTypes);
172
225
  ajv.addSchema(catalog, catalog.$id);
173
226
  instances = extractInstances(surface);
174
227
  // Manual discrimination instead of the flat `#/$defs/anyComponent`
@@ -201,7 +254,14 @@ export function validateCatalog(catalog, version, surface) {
201
254
  });
202
255
  continue;
203
256
  }
204
- const validateBranch = ajv.getSchema(`${catalog.$id}#/components/${comp}`);
257
+ // A 1.0 component is validated the way the envelope composes it (agent_to_renderer.json `Component`):
258
+ // ComponentCommon plus the catalog component, with no other property. A 0.9.1 component carries its own.
259
+ const validateBranch = commonTypes
260
+ ? ajv.compile({
261
+ allOf: [{ $ref: `${commonTypes.$id}#/$defs/ComponentCommon` }, { $ref: `${catalog.$id}#/components/${comp}` }],
262
+ unevaluatedProperties: false,
263
+ })
264
+ : ajv.getSchema(`${catalog.$id}#/components/${comp}`);
205
265
  if (!validateBranch) {
206
266
  failures.push(`${where}: could not resolve #/components/${comp} from the catalog.`);
207
267
  continue;
@@ -232,7 +292,9 @@ export function validateCatalog(catalog, version, surface) {
232
292
  name: "instance",
233
293
  pass: failures.length === 0,
234
294
  detail: failures.length === 0
235
- ? `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
295
+ ? version === "1.0"
296
+ ? `All ${instances.length} surface component instance(s) validate as the 1.0 envelope composes them: common_types.json ComponentCommon with the catalog component, closed.`
297
+ : `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
236
298
  : `${failures.length} instance validation error(s).`,
237
299
  errors: failures.length ? failures : undefined,
238
300
  ...(errorDetails.length ? { errorDetails } : {}),
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Runtime mirrors of the pinned A2UI 1.0 schemas (fixtures/a2ui/PIN.md): the official catalog definition, which is the
3
+ * 1.0 catalog-shape gate, and the final common_types, which a 1.0 catalog references for every standard type. They are
4
+ * constants because validation must also run in a browser bundle; src/schema-mirrors.test.ts keeps each identical to
5
+ * its vendored file. Do not edit by hand: re-vendor the fixture and regenerate this module.
6
+ */
7
+ import type { Json } from "../../types.js";
8
+ export declare const catalogDefinitionV1_0: Json;
9
+ export declare const commonTypesV1_0: Json;