@polyxd/a2ui 0.1.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/dist/a2ui.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /** Value of the `version` field on every emitted message. */
2
+ export declare const A2UI_VERSION = "v1.0";
3
+ /** Commit of a2ui-project/a2ui the vendored schemas were taken from. */
4
+ export declare const A2UI_COMMIT = "04e6f07fde12ff2638b3b489bd9e3033066cb957";
5
+ /** `catalogId` (and `$id`) of the Polyxd A2UI catalog. */
6
+ export declare const POLYXD_CATALOG_ID = "https://polyxd.com/catalog/0.1/a2ui";
7
+ /** `catalogId` of the official Basic catalog (for reference; the exporter does not emit Basic components). */
8
+ export declare const BASIC_CATALOG_ID = "https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json";
9
+ /**
10
+ * Key under `metadata.extensions` for Polyxd metadata that has no A2UI equivalent.
11
+ * Third-party extension keys must be prefixed with an organisation id (A2UI v1.0 §Extensions); this is polyxd.com reversed.
12
+ */
13
+ export declare const EXTENSION_KEY = "com_polyxd";
14
+ export type Json = Record<string, any>;
15
+ export declare const loadVendored: (path: string) => Json;
16
+ /** The official schemas the exporter is checked against. */
17
+ export declare const a2uiSchemas: {
18
+ agentToRenderer: () => Json;
19
+ commonTypes: () => Json;
20
+ catalogDefinition: () => Json;
21
+ basicCatalog: () => Json;
22
+ };
package/dist/a2ui.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Constants for the A2UI target and loaders for the vendored official schemas.
3
+ * See vendor/a2ui/<version>/README.md for provenance.
4
+ */
5
+ import { readFileSync } from "node:fs";
6
+ /** Value of the `version` field on every emitted message. */
7
+ export const A2UI_VERSION = "v1.0";
8
+ /** Commit of a2ui-project/a2ui the vendored schemas were taken from. */
9
+ export const A2UI_COMMIT = "04e6f07fde12ff2638b3b489bd9e3033066cb957";
10
+ /** `catalogId` (and `$id`) of the Polyxd A2UI catalog. */
11
+ export const POLYXD_CATALOG_ID = "https://polyxd.com/catalog/0.1/a2ui";
12
+ /** `catalogId` of the official Basic catalog (for reference; the exporter does not emit Basic components). */
13
+ export const BASIC_CATALOG_ID = "https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json";
14
+ /**
15
+ * Key under `metadata.extensions` for Polyxd metadata that has no A2UI equivalent.
16
+ * Third-party extension keys must be prefixed with an organisation id (A2UI v1.0 §Extensions); this is polyxd.com reversed.
17
+ */
18
+ export const EXTENSION_KEY = "com_polyxd";
19
+ const VENDOR_DIR = new URL("../vendor/a2ui/v1_0-04e6f07/", import.meta.url);
20
+ export const loadVendored = (path) => JSON.parse(readFileSync(new URL(path, VENDOR_DIR), "utf8"));
21
+ /** The official schemas the exporter is checked against. */
22
+ export const a2uiSchemas = {
23
+ agentToRenderer: () => loadVendored("json/agent_to_renderer.json"),
24
+ commonTypes: () => loadVendored("json/common_types.json"),
25
+ catalogDefinition: () => loadVendored("json/catalog_definition.json"),
26
+ basicCatalog: () => loadVendored("catalogs/basic/catalog.json"),
27
+ };
28
+ //# sourceMappingURL=a2ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui.js","sourceRoot":"","sources":["../src/a2ui.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AACnC,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,0CAA0C,CAAC;AACtE,0DAA0D;AAC1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,qCAAqC,CAAC;AACvE,8GAA8G;AAC9G,MAAM,CAAC,MAAM,gBAAgB,GAAG,iEAAiE,CAAC;AAClG;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,8BAA8B,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAI5E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,eAAe,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,6BAA6B,CAAC;IAClE,WAAW,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,wBAAwB,CAAC;IACzD,iBAAiB,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,8BAA8B,CAAC;IACrE,YAAY,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,6BAA6B,CAAC;CAChE,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { type Json } from "./a2ui.ts";
2
+ /** Renderer-handled Polyxd actions (`ui.*`), exported as A2UI local function calls. */
3
+ export declare const RENDERER_FUNCTIONS: Record<string, {
4
+ fn: string;
5
+ description: string;
6
+ }>;
7
+ interface ComponentSource {
8
+ name: string;
9
+ category: string;
10
+ summary: string;
11
+ props: Record<string, Json>;
12
+ required: string[];
13
+ whenToUse: string[];
14
+ whenNotToUse: string[];
15
+ accessibility: {
16
+ role: string;
17
+ requirements: string[];
18
+ };
19
+ agent: string;
20
+ rendering: string[];
21
+ a2ui: string;
22
+ }
23
+ export declare function loadPolyxdSources(): {
24
+ common: Record<string, Json>;
25
+ components: ComponentSource[];
26
+ };
27
+ export declare function buildInstructions(components: ComponentSource[]): string;
28
+ export declare function buildCatalog(): Json;
29
+ export declare const catalogJson: () => string;
30
+ export declare const CATALOG_FILE: URL;
31
+ /** The committed catalog (catalog/catalog.json). */
32
+ export declare const loadPolyxdCatalog: () => Json;
33
+ export {};
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Builds the Polyxd catalog in A2UI v1.0 catalog format from the Polyxd component sources
3
+ * (@polyxd/spec components/*.json + schema/common.defs.json).
4
+ *
5
+ * A2UI catalog rules this follows (A2UI v1.0 protocol, "Catalog Schema Rules and Conventions"):
6
+ * - top-level keys limited to $schema, $id, protocolVersion, title, description, catalogId, instructions, components, functions, $defs
7
+ * - $defs holds only anyComponent / anyFunction; no shared helpers, so Polyxd helper types are inlined per prop
8
+ * - external $refs only to common_types.json ComponentId, ChildList, Dynamic*, AccessibilityAttributes, CheckRule, Checkable, Action
9
+ * - component ids use ComponentId, child lists and templates use ChildList (validators find links by these refs)
10
+ * - id / catalogId / accessibility / metadata are envelope-level (ComponentCommon) and are not redeclared
11
+ */
12
+ import { readdirSync, readFileSync } from "node:fs";
13
+ import { EXTENSION_KEY, POLYXD_CATALOG_ID } from "./a2ui.js";
14
+ import { REFERENCE_TYPES } from "@polyxd/spec";
15
+ import { MAPPING } from "./mapping.js";
16
+ const COMMON = "common_types.json#/$defs/";
17
+ /** Polyxd defs that map one-to-one onto an A2UI common type. */
18
+ const DIRECT = {
19
+ Id: "ComponentId",
20
+ DynamicString: "DynamicString",
21
+ DynamicNumber: "DynamicNumber",
22
+ DynamicBoolean: "DynamicBoolean",
23
+ DynamicValue: "DynamicValue",
24
+ Accessibility: "AccessibilityAttributes",
25
+ Action: "Action",
26
+ };
27
+ /**
28
+ * A2UI `allowedChildren` for one component: emitted only when EVERY slot that can hold other
29
+ * components is restricted to named types. Derived from the spec's REFERENCE_TYPES, so the two
30
+ * can't drift apart (a component with a free-form `children` list stays unrestricted).
31
+ */
32
+ function allowedChildren(c) {
33
+ const refOf = (v) => {
34
+ const ref = v?.$ref;
35
+ return typeof ref === "string" ? ref : undefined;
36
+ };
37
+ // A Template holds any component as its repeated item, so it leaves the component unrestricted.
38
+ if (Object.values(c.props).some((v) => refOf(v)?.endsWith("/Template")))
39
+ return undefined;
40
+ const slots = Object.entries(c.props)
41
+ .filter(([, v]) => refOf(v)?.endsWith("/Id") || refOf(v)?.endsWith("/ChildList"))
42
+ .map(([k]) => k);
43
+ if (!slots.length)
44
+ return undefined;
45
+ const types = new Set();
46
+ for (const slot of slots) {
47
+ const allowed = REFERENCE_TYPES[`${c.name}.${slot}`];
48
+ if (!allowed)
49
+ return undefined;
50
+ for (const t of allowed)
51
+ types.add(t);
52
+ }
53
+ return [...types].sort();
54
+ }
55
+ /** Renderer-handled Polyxd actions (`ui.*`), exported as A2UI local function calls. */
56
+ export const RENDERER_FUNCTIONS = {
57
+ "ui.dismiss": { fn: "dismiss", description: "Closes the surface without doing anything (Polyxd 'ui.dismiss')." },
58
+ "ui.back": { fn: "back", description: "Returns to the previous step or surface (Polyxd 'ui.back')." },
59
+ "ui.next": { fn: "next", description: "Advances to the next step (Polyxd 'ui.next')." },
60
+ };
61
+ const specRoot = new URL("./", import.meta.resolve("@polyxd/spec/package.json"));
62
+ const readSpec = (p) => JSON.parse(readFileSync(new URL(p, specRoot), "utf8"));
63
+ export function loadPolyxdSources() {
64
+ const files = readdirSync(new URL("components/", specRoot)).filter((f) => f.endsWith(".json")).sort();
65
+ return { common: readSpec("schema/common.defs.json"), components: files.map((f) => readSpec(`components/${f}`)) };
66
+ }
67
+ /** Rewrites a Polyxd prop schema into an A2UI-catalog-compliant one (allowed $refs only, helpers inlined). */
68
+ function convert(schema, common) {
69
+ if (Array.isArray(schema))
70
+ return schema.map((s) => convert(s, common));
71
+ if (!schema || typeof schema !== "object")
72
+ return schema;
73
+ const s = schema;
74
+ if (typeof s.$ref === "string") {
75
+ const name = s.$ref.replace("#/$defs/", "");
76
+ const { $ref: _ref, ...siblings } = s;
77
+ const extra = convert(siblings, common);
78
+ if (name === "ChildList") {
79
+ return { $ref: `${COMMON}ChildList`, type: "array", minItems: 1, description: common.ChildList.description, ...extra };
80
+ }
81
+ if (name === "Template") {
82
+ return { $ref: `${COMMON}ChildList`, type: "object", description: common.Template.description, ...extra };
83
+ }
84
+ if (DIRECT[name])
85
+ return { $ref: `${COMMON}${DIRECT[name]}`, ...extra };
86
+ const def = common[name];
87
+ if (!def)
88
+ throw new Error(`unknown Polyxd def ${name}`);
89
+ return { ...convert(def, common), ...extra };
90
+ }
91
+ return Object.fromEntries(Object.entries(s).map(([k, v]) => [k, k === "enum" || k === "const" || k === "default" ? v : convert(v, common)]));
92
+ }
93
+ const bullets = (items) => items.map((x) => ` - ${x}`).join("\n");
94
+ export function buildInstructions(components) {
95
+ const head = `# Polyxd catalog for A2UI
96
+
97
+ Semantic components for just-in-time interfaces. The renderer maps each one onto its own native, design-system components and tokens. Pick components by meaning, not by look. Never send colours, sizes or fonts.
98
+
99
+ ## Rules for every surface
100
+
101
+ 1. The top-level component has \`"id": "root"\`. Children are referenced by id (flat adjacency list), never nested inline.
102
+ 2. Data always comes from the host through JSON Pointer bindings \`{"path": "/..."}\`. Never invent data or pre-format numbers and dates into strings. Set \`format\` instead.
103
+ 3. Inside a templated list (\`Collection.items\`), relative paths such as \`{"path": "title"}\` resolve against the current item. Absolute paths start with \`/\`.
104
+ 4. Actions are declared capability intents: \`{"event": {"name": "transfer.confirm", "context": {...}}}\`. Use \`{"functionCall": {"call": "dismiss" | "back" | "next"}}\` for navigation the renderer handles itself.
105
+ 5. At most one primary action is visible at a time. A Form's submit and a Steps finish count as primary.
106
+ 6. Destructive or consequential actions go through \`Confirm\`.
107
+ 7. Components carry their own roles and names. Use \`accessibility\` only to add to them.
108
+
109
+ ## Components
110
+ `;
111
+ const body = components.map((c) => [
112
+ `### ${c.name}`,
113
+ "",
114
+ c.summary,
115
+ "",
116
+ `- **Use when:**\n${bullets(c.whenToUse)}`,
117
+ `- **Don't use when:**\n${bullets(c.whenNotToUse)}`,
118
+ `- **Rendering:**\n${bullets(c.rendering)}`,
119
+ `- **Accessibility** (role: ${c.accessibility.role}):\n${bullets(c.accessibility.requirements)}`,
120
+ `- **Agents:** ${c.agent}`,
121
+ ].join("\n"));
122
+ return head + "\n" + body.join("\n\n") + "\n";
123
+ }
124
+ export function buildCatalog() {
125
+ const { common, components } = loadPolyxdSources();
126
+ const defs = {};
127
+ for (const c of components) {
128
+ const decision = MAPPING[c.name];
129
+ if (!decision)
130
+ throw new Error(`no A2UI mapping decision for ${c.name} (add it to src/mapping.ts)`);
131
+ const props = {
132
+ component: { const: c.name },
133
+ visible: { $ref: `${COMMON}DynamicBoolean`, description: "Hide the component when false" },
134
+ };
135
+ for (const [k, v] of Object.entries(c.props))
136
+ props[k] = convert(v, common);
137
+ defs[c.name] = {
138
+ type: "object",
139
+ description: c.summary,
140
+ properties: props,
141
+ required: ["component", ...c.required],
142
+ ...(allowedChildren(c) ? { allowedChildren: allowedChildren(c) } : {}),
143
+ metadata: {
144
+ extensions: {
145
+ [EXTENSION_KEY]: { category: c.category, target: decision.target, basicAnalog: decision.basicAnalog, why: decision.why },
146
+ },
147
+ },
148
+ };
149
+ }
150
+ const functions = {};
151
+ for (const { fn, description } of Object.values(RENDERER_FUNCTIONS)) {
152
+ functions[fn] = {
153
+ type: "object",
154
+ description,
155
+ returnType: "void",
156
+ allowedCallers: "rendererOnly",
157
+ properties: { call: { const: fn } },
158
+ required: ["call"],
159
+ };
160
+ }
161
+ return {
162
+ $schema: "https://json-schema.org/draft/2020-12/schema",
163
+ $id: POLYXD_CATALOG_ID,
164
+ protocolVersion: "1.0",
165
+ title: "Polyxd catalog",
166
+ description: "Polyxd semantic components as an A2UI v1.0 catalog. Every component is a faithful projection of the Polyxd component with the same name and props. Generated from @polyxd/spec components/*.json by @polyxd/a2ui (npm run build:catalog).",
167
+ catalogId: POLYXD_CATALOG_ID,
168
+ instructions: buildInstructions(components),
169
+ components: defs,
170
+ functions,
171
+ $defs: {
172
+ anyComponent: {
173
+ oneOf: components.map((c) => ({ $ref: `#/components/${c.name}` })),
174
+ discriminator: { propertyName: "component" },
175
+ },
176
+ anyFunction: { oneOf: Object.keys(functions).map((f) => ({ $ref: `#/functions/${f}` })) },
177
+ },
178
+ };
179
+ }
180
+ export const catalogJson = () => JSON.stringify(buildCatalog(), null, 2) + "\n";
181
+ export const CATALOG_FILE = new URL("../catalog/catalog.json", import.meta.url);
182
+ /** The committed catalog (catalog/catalog.json). */
183
+ export const loadPolyxdCatalog = () => JSON.parse(readFileSync(CATALOG_FILE, "utf8"));
184
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAa,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAE3C,gEAAgE;AAChE,MAAM,MAAM,GAA2B;IACrC,EAAE,EAAE,aAAa;IACjB,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,yBAAyB;IACxC,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF;;;;GAIG;AACH,SAAS,eAAe,CAAC,CAAkB;IACzC,MAAM,KAAK,GAAG,CAAC,CAAU,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAI,CAAU,EAAE,IAAI,CAAC;QAC9B,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC,CAAC;IACF,gGAAgG;IAChG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1F,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,K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8C;QACvD,GAAG,EAAE,iBAAiB;QACtB,eAAe,EAAE,KAAK;QACtB,KAAK,EAAE,gBAAgB;QACvB,WAAW,EACT,2OAA2O;QAC7O,SAAS,EAAE,iBAAiB;QAC5B,YAAY,EAAE,iBAAiB,CAAC,UAAU,CAAC;QAC3C,UAAU,EAAE,IAAI;QAChB,SAAS;QACT,KAAK,EAAE;YACL,YAAY,EAAE;gBACZ,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAClE,aAAa,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE;aAC7C;YACD,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE;SAC1F;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;AAEhF,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,yBAAyB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAEhF,oDAAoD;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAS,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { A2UI_VERSION, type Json } from "./a2ui.ts";
2
+ export interface PolyxdComponent {
3
+ id: string;
4
+ component: string;
5
+ key?: string;
6
+ accessibility?: Json;
7
+ [prop: string]: unknown;
8
+ }
9
+ export interface PolyxdDocument {
10
+ $schema?: string;
11
+ specVersion: string;
12
+ surface: {
13
+ id: string;
14
+ title: string;
15
+ intent?: string;
16
+ pattern?: string;
17
+ journey?: string;
18
+ dismissible?: boolean;
19
+ };
20
+ root: string;
21
+ components: PolyxdComponent[];
22
+ data?: Json;
23
+ }
24
+ export interface A2UIComponent {
25
+ id: string;
26
+ component: string;
27
+ accessibility?: Json;
28
+ metadata?: {
29
+ extensions: Json;
30
+ };
31
+ [prop: string]: unknown;
32
+ }
33
+ export type A2UIMessage = {
34
+ version: typeof A2UI_VERSION;
35
+ createSurface: {
36
+ surfaceId: string;
37
+ catalogId: string;
38
+ sendDataModel?: boolean;
39
+ components?: A2UIComponent[];
40
+ dataModel?: Json;
41
+ metadata?: {
42
+ extensions: Json;
43
+ };
44
+ };
45
+ } | {
46
+ version: typeof A2UI_VERSION;
47
+ updateComponents: {
48
+ surfaceId: string;
49
+ components: A2UIComponent[];
50
+ };
51
+ } | {
52
+ version: typeof A2UI_VERSION;
53
+ updateDataModel: {
54
+ surfaceId: string;
55
+ path?: string;
56
+ value: unknown;
57
+ };
58
+ };
59
+ export interface ExportOptions {
60
+ /**
61
+ * "inline" (default): one `createSurface` carrying `components` and `dataModel` (allowed by v1.0).
62
+ * "stream": `createSurface`, then `updateComponents`, then `updateDataModel` (only when the document has data).
63
+ */
64
+ mode?: "inline" | "stream";
65
+ /** Override the A2UI surfaceId (must be unique for the renderer's lifetime). Defaults to `surface.id`. */
66
+ surfaceId?: string;
67
+ /** Carry Polyxd-only metadata in `metadata.extensions.com_polyxd` (default true). The fields are listed in `lossy` either way. */
68
+ extensions?: boolean;
69
+ /** Passed through to createSurface.sendDataModel. */
70
+ sendDataModel?: boolean;
71
+ }
72
+ export interface ExportResult {
73
+ messages: A2UIMessage[];
74
+ /** JSON Pointers into the Polyxd document for every field with no A2UI representation. */
75
+ lossy: string[];
76
+ /** Component ids that were renamed (Polyxd id → A2UI id). Only "root" handling renames. */
77
+ idMap: Record<string, string>;
78
+ }
79
+ export declare function exportToA2UI(doc: PolyxdDocument, options?: ExportOptions): ExportResult;
package/dist/export.js ADDED
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Polyxd UI document → A2UI v1.0 agent-to-renderer message stream.
3
+ *
4
+ * The Polyxd component layer mirrors A2UI's shapes (flat adjacency list, JSON Pointer bindings,
5
+ * `action.event {name, context}`, `accessibility`), and the Polyxd A2UI catalog declares every component
6
+ * with its Polyxd props. So most of the export is an identity projection. The exceptions are:
7
+ * - the top-level component is renamed to "root" (A2UI mounts the component with id "root"),
8
+ * - `ui.*` renderer actions become A2UI local function calls (`dismiss` / `back` / `next`),
9
+ * - Polyxd metadata with no A2UI equivalent (spec version, surface title/intent/pattern/journey/dismissible,
10
+ * component `key`) is listed in `lossy`. Unless `extensions: false`, it is also carried as opaque
11
+ * `metadata.extensions.com_polyxd`, which A2UI renderers must ignore.
12
+ */
13
+ import { readFileSync } from "node:fs";
14
+ import { A2UI_VERSION, EXTENSION_KEY, POLYXD_CATALOG_ID } from "./a2ui.js";
15
+ import { RENDERER_FUNCTIONS } from "./catalog.js";
16
+ const uiSchema = JSON.parse(readFileSync(new URL(import.meta.resolve("@polyxd/spec/schema/ui.schema.json")), "utf8"));
17
+ const defs = uiSchema.$defs;
18
+ const refName = (s) => (typeof s?.$ref === "string" ? s.$ref.replace("#/$defs/", "") : undefined);
19
+ const deref = (s) => {
20
+ let cur = s;
21
+ while (cur && refName(cur))
22
+ cur = defs[refName(cur)];
23
+ return cur;
24
+ };
25
+ const pointer = (...parts) => "/" + parts.map((p) => String(p).replace(/~/g, "~0").replace(/\//g, "~1")).join("/");
26
+ const clone = (v) => structuredClone(v);
27
+ /** Fields of the Polyxd envelope that A2UI has no place for. */
28
+ const SURFACE_ONLY = ["title", "intent", "pattern", "journey", "dismissible"];
29
+ export function exportToA2UI(doc, options = {}) {
30
+ const { mode = "inline", extensions = true } = options;
31
+ const surfaceId = options.surfaceId ?? doc.surface.id;
32
+ const lossy = [];
33
+ // A2UI mounts the component with id "root". Rename the Polyxd root, moving any other "root" out of the way.
34
+ const ids = new Set(doc.components.map((c) => c.id));
35
+ const idMap = {};
36
+ if (doc.root !== "root") {
37
+ if (ids.has("root")) {
38
+ let n = 2;
39
+ while (ids.has(`root_${n}`))
40
+ n++;
41
+ idMap.root = `root_${n}`;
42
+ }
43
+ idMap[doc.root] = "root";
44
+ }
45
+ const mapId = (id) => idMap[id] ?? id;
46
+ /** Copies a prop value, rewriting component ids and renderer actions where the Polyxd schema says they are. */
47
+ const project = (schema, value, at) => {
48
+ const name = refName(schema);
49
+ if (name === "Id" && typeof value === "string")
50
+ return mapId(value);
51
+ if (name === "Action" && value && typeof value === "object")
52
+ return projectAction(value, at);
53
+ if (name === "Template" && value && typeof value === "object") {
54
+ const t = value;
55
+ return { ...clone(t), componentId: mapId(t.componentId) };
56
+ }
57
+ const s = deref(schema);
58
+ if (!s || s.oneOf || value === null || typeof value !== "object")
59
+ return clone(value);
60
+ if (Array.isArray(value))
61
+ return value.map((v, i) => project(s.items, v, `${at}/${i}`));
62
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, project(s.properties?.[k], v, `${at}/${k}`)]));
63
+ };
64
+ const projectAction = (action, at) => {
65
+ const fn = RENDERER_FUNCTIONS[action.event?.name];
66
+ if (!fn)
67
+ return clone(action);
68
+ if (action.event.context)
69
+ lossy.push(`${at}/event/context`);
70
+ return { functionCall: { call: fn.fn } };
71
+ };
72
+ const components = doc.components.map((c, i) => {
73
+ const compSchema = defs[`Component${c.component}`];
74
+ const out = { id: mapId(c.id), component: c.component };
75
+ for (const [prop, value] of Object.entries(c)) {
76
+ if (prop === "id" || prop === "component")
77
+ continue;
78
+ if (prop === "key") {
79
+ lossy.push(pointer("components", i, "key"));
80
+ continue;
81
+ }
82
+ out[prop] = project(compSchema?.properties?.[prop], value, pointer("components", i, prop));
83
+ }
84
+ if (extensions && c.key !== undefined)
85
+ out.metadata = { extensions: { [EXTENSION_KEY]: { key: c.key } } };
86
+ return out;
87
+ });
88
+ // Envelope fields.
89
+ const surfaceExt = {};
90
+ if (doc.$schema !== undefined)
91
+ lossy.push("/$schema");
92
+ if (doc.specVersion !== undefined)
93
+ (lossy.push("/specVersion"), (surfaceExt.specVersion = doc.specVersion));
94
+ for (const f of SURFACE_ONLY) {
95
+ if (doc.surface[f] !== undefined)
96
+ (lossy.push(`/surface/${f}`), (surfaceExt[f] = doc.surface[f]));
97
+ }
98
+ if (doc.root !== "root")
99
+ surfaceExt.root = doc.root;
100
+ const createSurface = { surfaceId, catalogId: POLYXD_CATALOG_ID };
101
+ if (options.sendDataModel !== undefined)
102
+ createSurface.sendDataModel = options.sendDataModel;
103
+ if (extensions && Object.keys(surfaceExt).length)
104
+ createSurface.metadata = { extensions: { [EXTENSION_KEY]: surfaceExt } };
105
+ const messages = [];
106
+ if (mode === "inline") {
107
+ createSurface.components = components;
108
+ if (doc.data !== undefined)
109
+ createSurface.dataModel = clone(doc.data);
110
+ messages.push({ version: A2UI_VERSION, createSurface });
111
+ }
112
+ else {
113
+ messages.push({ version: A2UI_VERSION, createSurface });
114
+ messages.push({ version: A2UI_VERSION, updateComponents: { surfaceId, components } });
115
+ if (doc.data !== undefined)
116
+ messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, value: clone(doc.data) } });
117
+ }
118
+ return { messages, lossy, idMap };
119
+ }
120
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAa,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAgElD,MAAM,QAAQ,GAAS,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,OA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AAC,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC,CAAC;QACxD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QACtF,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/H,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { exportToA2UI, type ExportOptions, type ExportResult, type A2UIMessage, type A2UIComponent, type PolyxdDocument, type PolyxdComponent } from "./export.ts";
2
+ export { buildCatalog, catalogJson, loadPolyxdCatalog, CATALOG_FILE, RENDERER_FUNCTIONS } from "./catalog.ts";
3
+ export { createValidator, checkComponentTree, type A2UIValidator, type A2UIValidationError } from "./validate.ts";
4
+ export { MAPPING, type MappingDecision } from "./mapping.ts";
5
+ export { A2UI_VERSION, A2UI_COMMIT, POLYXD_CATALOG_ID, BASIC_CATALOG_ID, EXTENSION_KEY, a2uiSchemas } from "./a2ui.ts";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { exportToA2UI } from "./export.js";
2
+ export { buildCatalog, catalogJson, loadPolyxdCatalog, CATALOG_FILE, RENDERER_FUNCTIONS } from "./catalog.js";
3
+ export { createValidator, checkComponentTree } from "./validate.js";
4
+ export { MAPPING } from "./mapping.js";
5
+ export { A2UI_VERSION, A2UI_COMMIT, POLYXD_CATALOG_ID, BASIC_CATALOG_ID, EXTENSION_KEY, a2uiSchemas } from "./a2ui.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0H,MAAM,aAAa,CAAC;AACnK,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAgD,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,OAAO,EAAwB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Per-component export decision: Basic catalog component, or a custom component in the Polyxd A2UI catalog.
3
+ *
4
+ * Rule: a Polyxd component maps to a Basic component only when every Polyxd prop has a Basic
5
+ * equivalent with the same meaning. Otherwise it is exported as a custom component with the same name and
6
+ * props, so the export stays a lossless projection rather than a lossy flattening
7
+ * (docs/decisions/0001 §6: "a faithful export", custom catalogs being the endorsed A2UI path).
8
+ * None of the 26 components currently meets the rule. `basicAnalog` records the nearest Basic
9
+ * construct and `why` records what flattening into it would lose.
10
+ */
11
+ export interface MappingDecision {
12
+ target: "basic" | "custom";
13
+ /** Nearest construct in the A2UI v1.0 Basic catalog */
14
+ basicAnalog: string;
15
+ /** What exporting to the Basic analog would lose */
16
+ why: string;
17
+ }
18
+ export declare const MAPPING: Record<string, MappingDecision>;