@genkit-ai/a2ui 0.5.0-rc.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/LICENSE +202 -0
- package/README.md +314 -0
- package/lib/catalog.d.mts +70 -0
- package/lib/catalog.d.ts +70 -0
- package/lib/catalog.js +285 -0
- package/lib/catalog.js.map +1 -0
- package/lib/catalog.mjs +256 -0
- package/lib/catalog.mjs.map +1 -0
- package/lib/client.d.mts +59 -0
- package/lib/client.d.ts +59 -0
- package/lib/client.js +82 -0
- package/lib/client.js.map +1 -0
- package/lib/client.mjs +55 -0
- package/lib/client.mjs.map +1 -0
- package/lib/index.d.mts +8 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +62 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +36 -0
- package/lib/index.mjs.map +1 -0
- package/lib/loader.d.mts +70 -0
- package/lib/loader.d.ts +70 -0
- package/lib/loader.js +92 -0
- package/lib/loader.js.map +1 -0
- package/lib/loader.mjs +61 -0
- package/lib/loader.mjs.map +1 -0
- package/lib/middleware.d.mts +112 -0
- package/lib/middleware.d.ts +112 -0
- package/lib/middleware.js +259 -0
- package/lib/middleware.js.map +1 -0
- package/lib/middleware.mjs +240 -0
- package/lib/middleware.mjs.map +1 -0
- package/lib/parser.d.mts +132 -0
- package/lib/parser.d.ts +132 -0
- package/lib/parser.js +282 -0
- package/lib/parser.js.map +1 -0
- package/lib/parser.mjs +260 -0
- package/lib/parser.mjs.map +1 -0
- package/lib/part.d.mts +56 -0
- package/lib/part.d.ts +56 -0
- package/lib/part.js +52 -0
- package/lib/part.js.map +1 -0
- package/lib/part.mjs +26 -0
- package/lib/part.mjs.map +1 -0
- package/lib/types.d.mts +153 -0
- package/lib/types.d.ts +153 -0
- package/lib/types.js +38 -0
- package/lib/types.js.map +1 -0
- package/lib/types.mjs +11 -0
- package/lib/types.mjs.map +1 -0
- package/package.json +80 -0
package/lib/part.d.mts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Part } from 'genkit';
|
|
2
|
+
import { A2uiEnvelope, A2uiPart } from './types.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Helpers for working with the canonical "a2ui part" — a Genkit `data` part
|
|
21
|
+
* whose `data` is an object `{ envelopes }` wrapping an array of A2UI envelopes,
|
|
22
|
+
* tagged with {@link A2UI_MIME_TYPE}.
|
|
23
|
+
*
|
|
24
|
+
* These helpers operate on plain part-shaped objects (no Genkit runtime import),
|
|
25
|
+
* so they are safe to use on both the server and the browser. To pull envelopes
|
|
26
|
+
* off an agent stream, pass the chunk's parts:
|
|
27
|
+
* `a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content)`.
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** Builds an a2ui data part wrapping the given envelopes. */
|
|
33
|
+
declare function a2uiPart(envelopes: A2uiEnvelope[]): A2uiPart;
|
|
34
|
+
/** Type guard: is this part an a2ui data part? */
|
|
35
|
+
declare function isA2uiPart(part: unknown): part is A2uiPart;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts all A2UI envelopes carried by the given `parts`.
|
|
38
|
+
*
|
|
39
|
+
* This is the single entry point for reading envelopes off any part-carrying
|
|
40
|
+
* value: pass a message's, chunk's, or response's `content`. For example, to
|
|
41
|
+
* consume an agent stream:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* for await (const chunk of turn.stream) {
|
|
45
|
+
* const envelopes = a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* `parts` is nullable purely for call-site convenience (a chunk's content can
|
|
50
|
+
* be `undefined`); a nullish list is treated as empty.
|
|
51
|
+
*
|
|
52
|
+
* Returns `[]` for content that carries no a2ui parts (e.g. plain prose).
|
|
53
|
+
*/
|
|
54
|
+
declare function a2uiEnvelopesFromParts(parts: readonly Part[] | null | undefined): A2uiEnvelope[];
|
|
55
|
+
|
|
56
|
+
export { a2uiEnvelopesFromParts, a2uiPart, isA2uiPart };
|
package/lib/part.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Part } from 'genkit';
|
|
2
|
+
import { A2uiEnvelope, A2uiPart } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Helpers for working with the canonical "a2ui part" — a Genkit `data` part
|
|
21
|
+
* whose `data` is an object `{ envelopes }` wrapping an array of A2UI envelopes,
|
|
22
|
+
* tagged with {@link A2UI_MIME_TYPE}.
|
|
23
|
+
*
|
|
24
|
+
* These helpers operate on plain part-shaped objects (no Genkit runtime import),
|
|
25
|
+
* so they are safe to use on both the server and the browser. To pull envelopes
|
|
26
|
+
* off an agent stream, pass the chunk's parts:
|
|
27
|
+
* `a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content)`.
|
|
28
|
+
*
|
|
29
|
+
* @module
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** Builds an a2ui data part wrapping the given envelopes. */
|
|
33
|
+
declare function a2uiPart(envelopes: A2uiEnvelope[]): A2uiPart;
|
|
34
|
+
/** Type guard: is this part an a2ui data part? */
|
|
35
|
+
declare function isA2uiPart(part: unknown): part is A2uiPart;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts all A2UI envelopes carried by the given `parts`.
|
|
38
|
+
*
|
|
39
|
+
* This is the single entry point for reading envelopes off any part-carrying
|
|
40
|
+
* value: pass a message's, chunk's, or response's `content`. For example, to
|
|
41
|
+
* consume an agent stream:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* for await (const chunk of turn.stream) {
|
|
45
|
+
* const envelopes = a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* `parts` is nullable purely for call-site convenience (a chunk's content can
|
|
50
|
+
* be `undefined`); a nullish list is treated as empty.
|
|
51
|
+
*
|
|
52
|
+
* Returns `[]` for content that carries no a2ui parts (e.g. plain prose).
|
|
53
|
+
*/
|
|
54
|
+
declare function a2uiEnvelopesFromParts(parts: readonly Part[] | null | undefined): A2uiEnvelope[];
|
|
55
|
+
|
|
56
|
+
export { a2uiEnvelopesFromParts, a2uiPart, isA2uiPart };
|
package/lib/part.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var part_exports = {};
|
|
20
|
+
__export(part_exports, {
|
|
21
|
+
a2uiEnvelopesFromParts: () => a2uiEnvelopesFromParts,
|
|
22
|
+
a2uiPart: () => a2uiPart,
|
|
23
|
+
isA2uiPart: () => isA2uiPart
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(part_exports);
|
|
26
|
+
var import_types = require("./types.js");
|
|
27
|
+
function a2uiPart(envelopes) {
|
|
28
|
+
return {
|
|
29
|
+
data: { envelopes },
|
|
30
|
+
metadata: { mimeType: import_types.A2UI_MIME_TYPE }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function isA2uiPart(part) {
|
|
34
|
+
const p = part;
|
|
35
|
+
const data = p?.data;
|
|
36
|
+
return !!p && typeof p === "object" && !!data && typeof data === "object" && Array.isArray(data.envelopes) && p.metadata?.mimeType === import_types.A2UI_MIME_TYPE;
|
|
37
|
+
}
|
|
38
|
+
function a2uiEnvelopesFromParts(parts) {
|
|
39
|
+
if (!Array.isArray(parts)) return [];
|
|
40
|
+
const out = [];
|
|
41
|
+
for (const part of parts) {
|
|
42
|
+
if (isA2uiPart(part)) out.push(...part.data.envelopes);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
a2uiEnvelopesFromParts,
|
|
49
|
+
a2uiPart,
|
|
50
|
+
isA2uiPart
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=part.js.map
|
package/lib/part.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/part.ts"],"sourcesContent":["/**\n * Copyright 2026 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Helpers for working with the canonical \"a2ui part\" — a Genkit `data` part\n * whose `data` is an object `{ envelopes }` wrapping an array of A2UI envelopes,\n * tagged with {@link A2UI_MIME_TYPE}.\n *\n * These helpers operate on plain part-shaped objects (no Genkit runtime import),\n * so they are safe to use on both the server and the browser. To pull envelopes\n * off an agent stream, pass the chunk's parts:\n * `a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content)`.\n *\n * @module\n */\n\nimport { type Part } from 'genkit';\nimport { A2UI_MIME_TYPE, type A2uiEnvelope, type A2uiPart } from './types.js';\n\n/** A minimal structural view of a Genkit part for these helpers. */\ninterface PartLike {\n data?: unknown;\n metadata?: Record<string, unknown> | null;\n [key: string]: unknown;\n}\n\n/** Builds an a2ui data part wrapping the given envelopes. */\nexport function a2uiPart(envelopes: A2uiEnvelope[]): A2uiPart {\n return {\n data: { envelopes },\n metadata: { mimeType: A2UI_MIME_TYPE },\n };\n}\n\n/** Type guard: is this part an a2ui data part? */\nexport function isA2uiPart(part: unknown): part is A2uiPart {\n const p = part as PartLike | null | undefined;\n const data = p?.data as { envelopes?: unknown } | undefined;\n return (\n !!p &&\n typeof p === 'object' &&\n !!data &&\n typeof data === 'object' &&\n Array.isArray(data.envelopes) &&\n (p as PartLike).metadata?.mimeType === A2UI_MIME_TYPE\n );\n}\n\n/**\n * Extracts all A2UI envelopes carried by the given `parts`.\n *\n * This is the single entry point for reading envelopes off any part-carrying\n * value: pass a message's, chunk's, or response's `content`. For example, to\n * consume an agent stream:\n *\n * ```ts\n * for await (const chunk of turn.stream) {\n * const envelopes = a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content);\n * }\n * ```\n *\n * `parts` is nullable purely for call-site convenience (a chunk's content can\n * be `undefined`); a nullish list is treated as empty.\n *\n * Returns `[]` for content that carries no a2ui parts (e.g. plain prose).\n */\nexport function a2uiEnvelopesFromParts(\n parts: readonly Part[] | null | undefined\n): A2uiEnvelope[] {\n if (!Array.isArray(parts)) return [];\n const out: A2uiEnvelope[] = [];\n for (const part of parts) {\n if (isA2uiPart(part)) out.push(...part.data.envelopes);\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,mBAAiE;AAU1D,SAAS,SAAS,WAAqC;AAC5D,SAAO;AAAA,IACL,MAAM,EAAE,UAAU;AAAA,IAClB,UAAU,EAAE,UAAU,4BAAe;AAAA,EACvC;AACF;AAGO,SAAS,WAAW,MAAiC;AAC1D,QAAM,IAAI;AACV,QAAM,OAAO,GAAG;AAChB,SACE,CAAC,CAAC,KACF,OAAO,MAAM,YACb,CAAC,CAAC,QACF,OAAO,SAAS,YAChB,MAAM,QAAQ,KAAK,SAAS,KAC3B,EAAe,UAAU,aAAa;AAE3C;AAoBO,SAAS,uBACd,OACgB;AAChB,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,QAAM,MAAsB,CAAC;AAC7B,aAAW,QAAQ,OAAO;AACxB,QAAI,WAAW,IAAI,EAAG,KAAI,KAAK,GAAG,KAAK,KAAK,SAAS;AAAA,EACvD;AACA,SAAO;AACT;","names":[]}
|
package/lib/part.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { A2UI_MIME_TYPE } from "./types.mjs";
|
|
2
|
+
function a2uiPart(envelopes) {
|
|
3
|
+
return {
|
|
4
|
+
data: { envelopes },
|
|
5
|
+
metadata: { mimeType: A2UI_MIME_TYPE }
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function isA2uiPart(part) {
|
|
9
|
+
const p = part;
|
|
10
|
+
const data = p?.data;
|
|
11
|
+
return !!p && typeof p === "object" && !!data && typeof data === "object" && Array.isArray(data.envelopes) && p.metadata?.mimeType === A2UI_MIME_TYPE;
|
|
12
|
+
}
|
|
13
|
+
function a2uiEnvelopesFromParts(parts) {
|
|
14
|
+
if (!Array.isArray(parts)) return [];
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
if (isA2uiPart(part)) out.push(...part.data.envelopes);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
a2uiEnvelopesFromParts,
|
|
23
|
+
a2uiPart,
|
|
24
|
+
isA2uiPart
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=part.mjs.map
|
package/lib/part.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/part.ts"],"sourcesContent":["/**\n * Copyright 2026 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Helpers for working with the canonical \"a2ui part\" — a Genkit `data` part\n * whose `data` is an object `{ envelopes }` wrapping an array of A2UI envelopes,\n * tagged with {@link A2UI_MIME_TYPE}.\n *\n * These helpers operate on plain part-shaped objects (no Genkit runtime import),\n * so they are safe to use on both the server and the browser. To pull envelopes\n * off an agent stream, pass the chunk's parts:\n * `a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content)`.\n *\n * @module\n */\n\nimport { type Part } from 'genkit';\nimport { A2UI_MIME_TYPE, type A2uiEnvelope, type A2uiPart } from './types.mjs';\n\n/** A minimal structural view of a Genkit part for these helpers. */\ninterface PartLike {\n data?: unknown;\n metadata?: Record<string, unknown> | null;\n [key: string]: unknown;\n}\n\n/** Builds an a2ui data part wrapping the given envelopes. */\nexport function a2uiPart(envelopes: A2uiEnvelope[]): A2uiPart {\n return {\n data: { envelopes },\n metadata: { mimeType: A2UI_MIME_TYPE },\n };\n}\n\n/** Type guard: is this part an a2ui data part? */\nexport function isA2uiPart(part: unknown): part is A2uiPart {\n const p = part as PartLike | null | undefined;\n const data = p?.data as { envelopes?: unknown } | undefined;\n return (\n !!p &&\n typeof p === 'object' &&\n !!data &&\n typeof data === 'object' &&\n Array.isArray(data.envelopes) &&\n (p as PartLike).metadata?.mimeType === A2UI_MIME_TYPE\n );\n}\n\n/**\n * Extracts all A2UI envelopes carried by the given `parts`.\n *\n * This is the single entry point for reading envelopes off any part-carrying\n * value: pass a message's, chunk's, or response's `content`. For example, to\n * consume an agent stream:\n *\n * ```ts\n * for await (const chunk of turn.stream) {\n * const envelopes = a2uiEnvelopesFromParts(chunk.raw.modelChunk?.content);\n * }\n * ```\n *\n * `parts` is nullable purely for call-site convenience (a chunk's content can\n * be `undefined`); a nullish list is treated as empty.\n *\n * Returns `[]` for content that carries no a2ui parts (e.g. plain prose).\n */\nexport function a2uiEnvelopesFromParts(\n parts: readonly Part[] | null | undefined\n): A2uiEnvelope[] {\n if (!Array.isArray(parts)) return [];\n const out: A2uiEnvelope[] = [];\n for (const part of parts) {\n if (isA2uiPart(part)) out.push(...part.data.envelopes);\n }\n return out;\n}\n"],"mappings":"AA8BA,SAAS,sBAAwD;AAU1D,SAAS,SAAS,WAAqC;AAC5D,SAAO;AAAA,IACL,MAAM,EAAE,UAAU;AAAA,IAClB,UAAU,EAAE,UAAU,eAAe;AAAA,EACvC;AACF;AAGO,SAAS,WAAW,MAAiC;AAC1D,QAAM,IAAI;AACV,QAAM,OAAO,GAAG;AAChB,SACE,CAAC,CAAC,KACF,OAAO,MAAM,YACb,CAAC,CAAC,QACF,OAAO,SAAS,YAChB,MAAM,QAAQ,KAAK,SAAS,KAC3B,EAAe,UAAU,aAAa;AAE3C;AAoBO,SAAS,uBACd,OACgB;AAChB,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,QAAM,MAAsB,CAAC;AAC7B,aAAW,QAAQ,OAAO;AACxB,QAAI,WAAW,IAAI,EAAG,KAAI,KAAK,GAAG,KAAK,KAAK,SAAS;AAAA,EACvD;AACA,SAAO;AACT;","names":[]}
|
package/lib/types.d.mts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Shared A2UI protocol types and constants.
|
|
18
|
+
*
|
|
19
|
+
* This module is intentionally free of any Node-only dependencies so it can be
|
|
20
|
+
* imported both on the server (the {@link a2ui} middleware) and in the browser
|
|
21
|
+
* (the client transport helpers). It mirrors the wire shapes of the A2UI v0.9
|
|
22
|
+
* specification without depending on `@a2ui/web_core` (the renderer packages are
|
|
23
|
+
* only needed on the client).
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* The MIME type that identifies an A2UI payload. This is stamped onto the
|
|
29
|
+
* `metadata.mimeType` of the Genkit `data` part that carries A2UI envelopes,
|
|
30
|
+
* matching the A2A binding of the A2UI spec exactly.
|
|
31
|
+
*/
|
|
32
|
+
declare const A2UI_MIME_TYPE = "application/a2ui+json";
|
|
33
|
+
/** The default A2UI protocol version stamped on emitted envelopes. */
|
|
34
|
+
declare const A2UI_VERSION = "v0.9";
|
|
35
|
+
/**
|
|
36
|
+
* The catalog id of the A2UI "Basic Catalog" (v0.9). Surfaces created with the
|
|
37
|
+
* basic catalog reference this id, and the client renderer registers a catalog
|
|
38
|
+
* under the same id.
|
|
39
|
+
*/
|
|
40
|
+
declare const BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
41
|
+
/**
|
|
42
|
+
* The protocol versions this plugin knows how to emit. This is the single
|
|
43
|
+
* source of truth: {@link SupportedVersion} is derived from it, and the
|
|
44
|
+
* middleware's `version` config validates against it (so a typo like `'v0.10'`
|
|
45
|
+
* is rejected at config time rather than producing envelopes the renderer
|
|
46
|
+
* rejects at runtime).
|
|
47
|
+
*/
|
|
48
|
+
declare const SUPPORTED_VERSIONS: readonly ["v0.9", "v0.9.1"];
|
|
49
|
+
type SupportedVersion = (typeof SUPPORTED_VERSIONS)[number];
|
|
50
|
+
/**
|
|
51
|
+
* A single component entry in an A2UI adjacency list. UI is expressed as a flat
|
|
52
|
+
* list of components; the tree is reconstructed via `id` references. Exactly one
|
|
53
|
+
* component has `id: "root"`.
|
|
54
|
+
*
|
|
55
|
+
* Beyond `component`/`id`/`weight`, every component carries catalog-specific
|
|
56
|
+
* props (e.g. `text`, `children`, `child`, `action`), so this is intentionally
|
|
57
|
+
* open-ended.
|
|
58
|
+
*/
|
|
59
|
+
interface A2uiComponent {
|
|
60
|
+
/** The catalog component type name, e.g. `Text`, `Column`, `Button`. */
|
|
61
|
+
component: string;
|
|
62
|
+
/** The unique id of this component. Exactly one component must be `"root"`. */
|
|
63
|
+
id?: string;
|
|
64
|
+
/** Relative flex weight when nested directly in a Row/Column. */
|
|
65
|
+
weight?: number;
|
|
66
|
+
/** Catalog-specific component props. */
|
|
67
|
+
[prop: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
/** Creates (or re-initializes) a UI surface. */
|
|
70
|
+
interface CreateSurfaceEnvelope {
|
|
71
|
+
version: SupportedVersion;
|
|
72
|
+
createSurface: {
|
|
73
|
+
surfaceId: string;
|
|
74
|
+
catalogId: string;
|
|
75
|
+
theme?: unknown;
|
|
76
|
+
sendDataModel?: boolean;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Adds or replaces components on an existing surface. */
|
|
80
|
+
interface UpdateComponentsEnvelope {
|
|
81
|
+
version: SupportedVersion;
|
|
82
|
+
updateComponents: {
|
|
83
|
+
surfaceId: string;
|
|
84
|
+
components: A2uiComponent[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Mutates a value in a surface's per-surface data model. */
|
|
88
|
+
interface UpdateDataModelEnvelope {
|
|
89
|
+
version: SupportedVersion;
|
|
90
|
+
updateDataModel: {
|
|
91
|
+
surfaceId: string;
|
|
92
|
+
/** JSON-Pointer path. When omitted, `value` replaces the whole model. */
|
|
93
|
+
path?: string;
|
|
94
|
+
value?: unknown;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Removes a surface. */
|
|
98
|
+
interface DeleteSurfaceEnvelope {
|
|
99
|
+
version: SupportedVersion;
|
|
100
|
+
deleteSurface: {
|
|
101
|
+
surfaceId: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A user action reported by a rendered surface (client → server), wrapped as an
|
|
106
|
+
* envelope so it rides the same a2ui part channel as server → client envelopes.
|
|
107
|
+
* This is the typed shape {@link actionToMessage} produces and
|
|
108
|
+
* {@link A2uiEnvelope} recognizes on the way back in.
|
|
109
|
+
*/
|
|
110
|
+
interface ActionEnvelope {
|
|
111
|
+
action: A2uiClientAction;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A single A2UI envelope message.
|
|
115
|
+
*
|
|
116
|
+
* Most variants flow server → client (surfaces the agent renders); the
|
|
117
|
+
* {@link ActionEnvelope} variant flows client → server (a user interaction sent
|
|
118
|
+
* back as the next turn). Keeping both directions in one union lets
|
|
119
|
+
* {@link a2uiPart} be the single constructor for every a2ui part.
|
|
120
|
+
*/
|
|
121
|
+
type A2uiEnvelope = CreateSurfaceEnvelope | UpdateComponentsEnvelope | UpdateDataModelEnvelope | DeleteSurfaceEnvelope | ActionEnvelope;
|
|
122
|
+
/**
|
|
123
|
+
* The canonical "a2ui part": a Genkit `data` part whose `data` is an object
|
|
124
|
+
* `{ envelopes }` wrapping the array of A2UI envelopes, and whose
|
|
125
|
+
* `metadata.mimeType` is {@link A2UI_MIME_TYPE}.
|
|
126
|
+
*
|
|
127
|
+
* The array is wrapped in an object (rather than being the `data` value
|
|
128
|
+
* directly) so the payload is a `Map<String, dynamic>`-shaped object on every
|
|
129
|
+
* runtime — some (e.g. Dart) expect a data part's `data` to be an object, not a
|
|
130
|
+
* bare array.
|
|
131
|
+
*/
|
|
132
|
+
interface A2uiPart {
|
|
133
|
+
data: {
|
|
134
|
+
envelopes: A2uiEnvelope[];
|
|
135
|
+
};
|
|
136
|
+
metadata: {
|
|
137
|
+
mimeType: typeof A2UI_MIME_TYPE;
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A client → server user action reported by a rendered surface (e.g. a button
|
|
143
|
+
* press). Sent back to the agent as the next turn's input.
|
|
144
|
+
*/
|
|
145
|
+
interface A2uiClientAction {
|
|
146
|
+
name: string;
|
|
147
|
+
surfaceId: string;
|
|
148
|
+
sourceComponentId: string;
|
|
149
|
+
timestamp: string;
|
|
150
|
+
context: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { A2UI_MIME_TYPE, A2UI_VERSION, type A2uiClientAction, type A2uiComponent, type A2uiEnvelope, type A2uiPart, type ActionEnvelope, BASIC_CATALOG_ID, type CreateSurfaceEnvelope, type DeleteSurfaceEnvelope, SUPPORTED_VERSIONS, type SupportedVersion, type UpdateComponentsEnvelope, type UpdateDataModelEnvelope };
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Shared A2UI protocol types and constants.
|
|
18
|
+
*
|
|
19
|
+
* This module is intentionally free of any Node-only dependencies so it can be
|
|
20
|
+
* imported both on the server (the {@link a2ui} middleware) and in the browser
|
|
21
|
+
* (the client transport helpers). It mirrors the wire shapes of the A2UI v0.9
|
|
22
|
+
* specification without depending on `@a2ui/web_core` (the renderer packages are
|
|
23
|
+
* only needed on the client).
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* The MIME type that identifies an A2UI payload. This is stamped onto the
|
|
29
|
+
* `metadata.mimeType` of the Genkit `data` part that carries A2UI envelopes,
|
|
30
|
+
* matching the A2A binding of the A2UI spec exactly.
|
|
31
|
+
*/
|
|
32
|
+
declare const A2UI_MIME_TYPE = "application/a2ui+json";
|
|
33
|
+
/** The default A2UI protocol version stamped on emitted envelopes. */
|
|
34
|
+
declare const A2UI_VERSION = "v0.9";
|
|
35
|
+
/**
|
|
36
|
+
* The catalog id of the A2UI "Basic Catalog" (v0.9). Surfaces created with the
|
|
37
|
+
* basic catalog reference this id, and the client renderer registers a catalog
|
|
38
|
+
* under the same id.
|
|
39
|
+
*/
|
|
40
|
+
declare const BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
41
|
+
/**
|
|
42
|
+
* The protocol versions this plugin knows how to emit. This is the single
|
|
43
|
+
* source of truth: {@link SupportedVersion} is derived from it, and the
|
|
44
|
+
* middleware's `version` config validates against it (so a typo like `'v0.10'`
|
|
45
|
+
* is rejected at config time rather than producing envelopes the renderer
|
|
46
|
+
* rejects at runtime).
|
|
47
|
+
*/
|
|
48
|
+
declare const SUPPORTED_VERSIONS: readonly ["v0.9", "v0.9.1"];
|
|
49
|
+
type SupportedVersion = (typeof SUPPORTED_VERSIONS)[number];
|
|
50
|
+
/**
|
|
51
|
+
* A single component entry in an A2UI adjacency list. UI is expressed as a flat
|
|
52
|
+
* list of components; the tree is reconstructed via `id` references. Exactly one
|
|
53
|
+
* component has `id: "root"`.
|
|
54
|
+
*
|
|
55
|
+
* Beyond `component`/`id`/`weight`, every component carries catalog-specific
|
|
56
|
+
* props (e.g. `text`, `children`, `child`, `action`), so this is intentionally
|
|
57
|
+
* open-ended.
|
|
58
|
+
*/
|
|
59
|
+
interface A2uiComponent {
|
|
60
|
+
/** The catalog component type name, e.g. `Text`, `Column`, `Button`. */
|
|
61
|
+
component: string;
|
|
62
|
+
/** The unique id of this component. Exactly one component must be `"root"`. */
|
|
63
|
+
id?: string;
|
|
64
|
+
/** Relative flex weight when nested directly in a Row/Column. */
|
|
65
|
+
weight?: number;
|
|
66
|
+
/** Catalog-specific component props. */
|
|
67
|
+
[prop: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
/** Creates (or re-initializes) a UI surface. */
|
|
70
|
+
interface CreateSurfaceEnvelope {
|
|
71
|
+
version: SupportedVersion;
|
|
72
|
+
createSurface: {
|
|
73
|
+
surfaceId: string;
|
|
74
|
+
catalogId: string;
|
|
75
|
+
theme?: unknown;
|
|
76
|
+
sendDataModel?: boolean;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Adds or replaces components on an existing surface. */
|
|
80
|
+
interface UpdateComponentsEnvelope {
|
|
81
|
+
version: SupportedVersion;
|
|
82
|
+
updateComponents: {
|
|
83
|
+
surfaceId: string;
|
|
84
|
+
components: A2uiComponent[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Mutates a value in a surface's per-surface data model. */
|
|
88
|
+
interface UpdateDataModelEnvelope {
|
|
89
|
+
version: SupportedVersion;
|
|
90
|
+
updateDataModel: {
|
|
91
|
+
surfaceId: string;
|
|
92
|
+
/** JSON-Pointer path. When omitted, `value` replaces the whole model. */
|
|
93
|
+
path?: string;
|
|
94
|
+
value?: unknown;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Removes a surface. */
|
|
98
|
+
interface DeleteSurfaceEnvelope {
|
|
99
|
+
version: SupportedVersion;
|
|
100
|
+
deleteSurface: {
|
|
101
|
+
surfaceId: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A user action reported by a rendered surface (client → server), wrapped as an
|
|
106
|
+
* envelope so it rides the same a2ui part channel as server → client envelopes.
|
|
107
|
+
* This is the typed shape {@link actionToMessage} produces and
|
|
108
|
+
* {@link A2uiEnvelope} recognizes on the way back in.
|
|
109
|
+
*/
|
|
110
|
+
interface ActionEnvelope {
|
|
111
|
+
action: A2uiClientAction;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A single A2UI envelope message.
|
|
115
|
+
*
|
|
116
|
+
* Most variants flow server → client (surfaces the agent renders); the
|
|
117
|
+
* {@link ActionEnvelope} variant flows client → server (a user interaction sent
|
|
118
|
+
* back as the next turn). Keeping both directions in one union lets
|
|
119
|
+
* {@link a2uiPart} be the single constructor for every a2ui part.
|
|
120
|
+
*/
|
|
121
|
+
type A2uiEnvelope = CreateSurfaceEnvelope | UpdateComponentsEnvelope | UpdateDataModelEnvelope | DeleteSurfaceEnvelope | ActionEnvelope;
|
|
122
|
+
/**
|
|
123
|
+
* The canonical "a2ui part": a Genkit `data` part whose `data` is an object
|
|
124
|
+
* `{ envelopes }` wrapping the array of A2UI envelopes, and whose
|
|
125
|
+
* `metadata.mimeType` is {@link A2UI_MIME_TYPE}.
|
|
126
|
+
*
|
|
127
|
+
* The array is wrapped in an object (rather than being the `data` value
|
|
128
|
+
* directly) so the payload is a `Map<String, dynamic>`-shaped object on every
|
|
129
|
+
* runtime — some (e.g. Dart) expect a data part's `data` to be an object, not a
|
|
130
|
+
* bare array.
|
|
131
|
+
*/
|
|
132
|
+
interface A2uiPart {
|
|
133
|
+
data: {
|
|
134
|
+
envelopes: A2uiEnvelope[];
|
|
135
|
+
};
|
|
136
|
+
metadata: {
|
|
137
|
+
mimeType: typeof A2UI_MIME_TYPE;
|
|
138
|
+
[key: string]: unknown;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A client → server user action reported by a rendered surface (e.g. a button
|
|
143
|
+
* press). Sent back to the agent as the next turn's input.
|
|
144
|
+
*/
|
|
145
|
+
interface A2uiClientAction {
|
|
146
|
+
name: string;
|
|
147
|
+
surfaceId: string;
|
|
148
|
+
sourceComponentId: string;
|
|
149
|
+
timestamp: string;
|
|
150
|
+
context: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { A2UI_MIME_TYPE, A2UI_VERSION, type A2uiClientAction, type A2uiComponent, type A2uiEnvelope, type A2uiPart, type ActionEnvelope, BASIC_CATALOG_ID, type CreateSurfaceEnvelope, type DeleteSurfaceEnvelope, SUPPORTED_VERSIONS, type SupportedVersion, type UpdateComponentsEnvelope, type UpdateDataModelEnvelope };
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
A2UI_MIME_TYPE: () => A2UI_MIME_TYPE,
|
|
22
|
+
A2UI_VERSION: () => A2UI_VERSION,
|
|
23
|
+
BASIC_CATALOG_ID: () => BASIC_CATALOG_ID,
|
|
24
|
+
SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(types_exports);
|
|
27
|
+
const A2UI_MIME_TYPE = "application/a2ui+json";
|
|
28
|
+
const A2UI_VERSION = "v0.9";
|
|
29
|
+
const BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
30
|
+
const SUPPORTED_VERSIONS = ["v0.9", "v0.9.1"];
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
A2UI_MIME_TYPE,
|
|
34
|
+
A2UI_VERSION,
|
|
35
|
+
BASIC_CATALOG_ID,
|
|
36
|
+
SUPPORTED_VERSIONS
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * Copyright 2026 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Shared A2UI protocol types and constants.\n *\n * This module is intentionally free of any Node-only dependencies so it can be\n * imported both on the server (the {@link a2ui} middleware) and in the browser\n * (the client transport helpers). It mirrors the wire shapes of the A2UI v0.9\n * specification without depending on `@a2ui/web_core` (the renderer packages are\n * only needed on the client).\n *\n * @module\n */\n\n/**\n * The MIME type that identifies an A2UI payload. This is stamped onto the\n * `metadata.mimeType` of the Genkit `data` part that carries A2UI envelopes,\n * matching the A2A binding of the A2UI spec exactly.\n */\nexport const A2UI_MIME_TYPE = 'application/a2ui+json';\n\n/** The default A2UI protocol version stamped on emitted envelopes. */\nexport const A2UI_VERSION = 'v0.9';\n\n/**\n * The catalog id of the A2UI \"Basic Catalog\" (v0.9). Surfaces created with the\n * basic catalog reference this id, and the client renderer registers a catalog\n * under the same id.\n */\nexport const BASIC_CATALOG_ID =\n 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json';\n\n/**\n * The protocol versions this plugin knows how to emit. This is the single\n * source of truth: {@link SupportedVersion} is derived from it, and the\n * middleware's `version` config validates against it (so a typo like `'v0.10'`\n * is rejected at config time rather than producing envelopes the renderer\n * rejects at runtime).\n */\nexport const SUPPORTED_VERSIONS = ['v0.9', 'v0.9.1'] as const;\n\nexport type SupportedVersion = (typeof SUPPORTED_VERSIONS)[number];\n\n/**\n * A single component entry in an A2UI adjacency list. UI is expressed as a flat\n * list of components; the tree is reconstructed via `id` references. Exactly one\n * component has `id: \"root\"`.\n *\n * Beyond `component`/`id`/`weight`, every component carries catalog-specific\n * props (e.g. `text`, `children`, `child`, `action`), so this is intentionally\n * open-ended.\n */\nexport interface A2uiComponent {\n /** The catalog component type name, e.g. `Text`, `Column`, `Button`. */\n component: string;\n /** The unique id of this component. Exactly one component must be `\"root\"`. */\n id?: string;\n /** Relative flex weight when nested directly in a Row/Column. */\n weight?: number;\n /** Catalog-specific component props. */\n [prop: string]: unknown;\n}\n\n/** Creates (or re-initializes) a UI surface. */\nexport interface CreateSurfaceEnvelope {\n version: SupportedVersion;\n createSurface: {\n surfaceId: string;\n catalogId: string;\n theme?: unknown;\n sendDataModel?: boolean;\n };\n}\n\n/** Adds or replaces components on an existing surface. */\nexport interface UpdateComponentsEnvelope {\n version: SupportedVersion;\n updateComponents: {\n surfaceId: string;\n components: A2uiComponent[];\n };\n}\n\n/** Mutates a value in a surface's per-surface data model. */\nexport interface UpdateDataModelEnvelope {\n version: SupportedVersion;\n updateDataModel: {\n surfaceId: string;\n /** JSON-Pointer path. When omitted, `value` replaces the whole model. */\n path?: string;\n value?: unknown;\n };\n}\n\n/** Removes a surface. */\nexport interface DeleteSurfaceEnvelope {\n version: SupportedVersion;\n deleteSurface: {\n surfaceId: string;\n };\n}\n\n/**\n * A user action reported by a rendered surface (client → server), wrapped as an\n * envelope so it rides the same a2ui part channel as server → client envelopes.\n * This is the typed shape {@link actionToMessage} produces and\n * {@link A2uiEnvelope} recognizes on the way back in.\n */\nexport interface ActionEnvelope {\n action: A2uiClientAction;\n}\n\n/**\n * A single A2UI envelope message.\n *\n * Most variants flow server → client (surfaces the agent renders); the\n * {@link ActionEnvelope} variant flows client → server (a user interaction sent\n * back as the next turn). Keeping both directions in one union lets\n * {@link a2uiPart} be the single constructor for every a2ui part.\n */\nexport type A2uiEnvelope =\n | CreateSurfaceEnvelope\n | UpdateComponentsEnvelope\n | UpdateDataModelEnvelope\n | DeleteSurfaceEnvelope\n | ActionEnvelope;\n\n/**\n * The canonical \"a2ui part\": a Genkit `data` part whose `data` is an object\n * `{ envelopes }` wrapping the array of A2UI envelopes, and whose\n * `metadata.mimeType` is {@link A2UI_MIME_TYPE}.\n *\n * The array is wrapped in an object (rather than being the `data` value\n * directly) so the payload is a `Map<String, dynamic>`-shaped object on every\n * runtime — some (e.g. Dart) expect a data part's `data` to be an object, not a\n * bare array.\n */\nexport interface A2uiPart {\n data: { envelopes: A2uiEnvelope[] };\n metadata: {\n mimeType: typeof A2UI_MIME_TYPE;\n [key: string]: unknown;\n };\n}\n\n/**\n * A client → server user action reported by a rendered surface (e.g. a button\n * press). Sent back to the agent as the next turn's input.\n */\nexport interface A2uiClientAction {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n timestamp: string;\n context: Record<string, unknown>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCO,MAAM,iBAAiB;AAGvB,MAAM,eAAe;AAOrB,MAAM,mBACX;AASK,MAAM,qBAAqB,CAAC,QAAQ,QAAQ;","names":[]}
|
package/lib/types.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const A2UI_MIME_TYPE = "application/a2ui+json";
|
|
2
|
+
const A2UI_VERSION = "v0.9";
|
|
3
|
+
const BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
4
|
+
const SUPPORTED_VERSIONS = ["v0.9", "v0.9.1"];
|
|
5
|
+
export {
|
|
6
|
+
A2UI_MIME_TYPE,
|
|
7
|
+
A2UI_VERSION,
|
|
8
|
+
BASIC_CATALOG_ID,
|
|
9
|
+
SUPPORTED_VERSIONS
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * Copyright 2026 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Shared A2UI protocol types and constants.\n *\n * This module is intentionally free of any Node-only dependencies so it can be\n * imported both on the server (the {@link a2ui} middleware) and in the browser\n * (the client transport helpers). It mirrors the wire shapes of the A2UI v0.9\n * specification without depending on `@a2ui/web_core` (the renderer packages are\n * only needed on the client).\n *\n * @module\n */\n\n/**\n * The MIME type that identifies an A2UI payload. This is stamped onto the\n * `metadata.mimeType` of the Genkit `data` part that carries A2UI envelopes,\n * matching the A2A binding of the A2UI spec exactly.\n */\nexport const A2UI_MIME_TYPE = 'application/a2ui+json';\n\n/** The default A2UI protocol version stamped on emitted envelopes. */\nexport const A2UI_VERSION = 'v0.9';\n\n/**\n * The catalog id of the A2UI \"Basic Catalog\" (v0.9). Surfaces created with the\n * basic catalog reference this id, and the client renderer registers a catalog\n * under the same id.\n */\nexport const BASIC_CATALOG_ID =\n 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json';\n\n/**\n * The protocol versions this plugin knows how to emit. This is the single\n * source of truth: {@link SupportedVersion} is derived from it, and the\n * middleware's `version` config validates against it (so a typo like `'v0.10'`\n * is rejected at config time rather than producing envelopes the renderer\n * rejects at runtime).\n */\nexport const SUPPORTED_VERSIONS = ['v0.9', 'v0.9.1'] as const;\n\nexport type SupportedVersion = (typeof SUPPORTED_VERSIONS)[number];\n\n/**\n * A single component entry in an A2UI adjacency list. UI is expressed as a flat\n * list of components; the tree is reconstructed via `id` references. Exactly one\n * component has `id: \"root\"`.\n *\n * Beyond `component`/`id`/`weight`, every component carries catalog-specific\n * props (e.g. `text`, `children`, `child`, `action`), so this is intentionally\n * open-ended.\n */\nexport interface A2uiComponent {\n /** The catalog component type name, e.g. `Text`, `Column`, `Button`. */\n component: string;\n /** The unique id of this component. Exactly one component must be `\"root\"`. */\n id?: string;\n /** Relative flex weight when nested directly in a Row/Column. */\n weight?: number;\n /** Catalog-specific component props. */\n [prop: string]: unknown;\n}\n\n/** Creates (or re-initializes) a UI surface. */\nexport interface CreateSurfaceEnvelope {\n version: SupportedVersion;\n createSurface: {\n surfaceId: string;\n catalogId: string;\n theme?: unknown;\n sendDataModel?: boolean;\n };\n}\n\n/** Adds or replaces components on an existing surface. */\nexport interface UpdateComponentsEnvelope {\n version: SupportedVersion;\n updateComponents: {\n surfaceId: string;\n components: A2uiComponent[];\n };\n}\n\n/** Mutates a value in a surface's per-surface data model. */\nexport interface UpdateDataModelEnvelope {\n version: SupportedVersion;\n updateDataModel: {\n surfaceId: string;\n /** JSON-Pointer path. When omitted, `value` replaces the whole model. */\n path?: string;\n value?: unknown;\n };\n}\n\n/** Removes a surface. */\nexport interface DeleteSurfaceEnvelope {\n version: SupportedVersion;\n deleteSurface: {\n surfaceId: string;\n };\n}\n\n/**\n * A user action reported by a rendered surface (client → server), wrapped as an\n * envelope so it rides the same a2ui part channel as server → client envelopes.\n * This is the typed shape {@link actionToMessage} produces and\n * {@link A2uiEnvelope} recognizes on the way back in.\n */\nexport interface ActionEnvelope {\n action: A2uiClientAction;\n}\n\n/**\n * A single A2UI envelope message.\n *\n * Most variants flow server → client (surfaces the agent renders); the\n * {@link ActionEnvelope} variant flows client → server (a user interaction sent\n * back as the next turn). Keeping both directions in one union lets\n * {@link a2uiPart} be the single constructor for every a2ui part.\n */\nexport type A2uiEnvelope =\n | CreateSurfaceEnvelope\n | UpdateComponentsEnvelope\n | UpdateDataModelEnvelope\n | DeleteSurfaceEnvelope\n | ActionEnvelope;\n\n/**\n * The canonical \"a2ui part\": a Genkit `data` part whose `data` is an object\n * `{ envelopes }` wrapping the array of A2UI envelopes, and whose\n * `metadata.mimeType` is {@link A2UI_MIME_TYPE}.\n *\n * The array is wrapped in an object (rather than being the `data` value\n * directly) so the payload is a `Map<String, dynamic>`-shaped object on every\n * runtime — some (e.g. Dart) expect a data part's `data` to be an object, not a\n * bare array.\n */\nexport interface A2uiPart {\n data: { envelopes: A2uiEnvelope[] };\n metadata: {\n mimeType: typeof A2UI_MIME_TYPE;\n [key: string]: unknown;\n };\n}\n\n/**\n * A client → server user action reported by a rendered surface (e.g. a button\n * press). Sent back to the agent as the next turn's input.\n */\nexport interface A2uiClientAction {\n name: string;\n surfaceId: string;\n sourceComponentId: string;\n timestamp: string;\n context: Record<string, unknown>;\n}\n"],"mappings":"AAiCO,MAAM,iBAAiB;AAGvB,MAAM,eAAe;AAOrB,MAAM,mBACX;AASK,MAAM,qBAAqB,CAAC,QAAQ,QAAQ;","names":[]}
|