@mcp-native/a2ui 0.0.1 → 0.0.2
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 +1 -3
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -0
- package/package.json +27 -8
- package/index.js +0 -1
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ToolAction } from "@mcp-native/core";
|
|
2
|
+
export declare const A2UI_VERSION: "0.1";
|
|
3
|
+
interface A2uiNodeBase {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface A2uiContainerNode extends A2uiNodeBase {
|
|
7
|
+
readonly type: "container";
|
|
8
|
+
readonly children: readonly A2uiNode[];
|
|
9
|
+
}
|
|
10
|
+
export interface A2uiTextNode extends A2uiNodeBase {
|
|
11
|
+
readonly type: "text";
|
|
12
|
+
readonly text: string;
|
|
13
|
+
}
|
|
14
|
+
export interface A2uiButtonNode extends A2uiNodeBase {
|
|
15
|
+
readonly type: "button";
|
|
16
|
+
readonly label: string;
|
|
17
|
+
readonly action: ToolAction;
|
|
18
|
+
}
|
|
19
|
+
export interface A2uiTextInputNode extends A2uiNodeBase {
|
|
20
|
+
readonly type: "text-input";
|
|
21
|
+
readonly label: string;
|
|
22
|
+
readonly value?: string;
|
|
23
|
+
readonly binding?: string;
|
|
24
|
+
}
|
|
25
|
+
export type A2uiNode = A2uiButtonNode | A2uiContainerNode | A2uiTextInputNode | A2uiTextNode;
|
|
26
|
+
export interface A2uiSurface {
|
|
27
|
+
readonly version: typeof A2UI_VERSION;
|
|
28
|
+
readonly root: A2uiNode;
|
|
29
|
+
}
|
|
30
|
+
export declare class A2uiParseError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
export declare function parseA2uiSurface(input: string | unknown): A2uiSurface;
|
|
34
|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;IACvC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,CAsBrE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const A2UI_VERSION = "0.1";
|
|
2
|
+
export class A2uiParseError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "A2uiParseError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function parseA2uiSurface(input) {
|
|
9
|
+
let value = input;
|
|
10
|
+
if (typeof input === "string") {
|
|
11
|
+
try {
|
|
12
|
+
value = JSON.parse(input);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
const message = error instanceof Error ? error.message : "unknown JSON error";
|
|
16
|
+
throw new A2uiParseError(`Invalid JSON: ${message}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const surface = expectObject(value, "surface");
|
|
20
|
+
const version = expectString(surface.version, "surface.version");
|
|
21
|
+
if (version !== A2UI_VERSION) {
|
|
22
|
+
throw new A2uiParseError(`Unsupported A2UI version: ${version}`);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
version: A2UI_VERSION,
|
|
26
|
+
root: parseNode(surface.root, "surface.root"),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function parseNode(value, path) {
|
|
30
|
+
const node = expectObject(value, path);
|
|
31
|
+
const id = expectString(node.id, `${path}.id`);
|
|
32
|
+
const type = expectString(node.type, `${path}.type`);
|
|
33
|
+
switch (type) {
|
|
34
|
+
case "container":
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
type,
|
|
38
|
+
children: expectArray(node.children, `${path}.children`).map((child, index) => parseNode(child, `${path}.children[${index}]`)),
|
|
39
|
+
};
|
|
40
|
+
case "text":
|
|
41
|
+
return { id, type, text: expectString(node.text, `${path}.text`) };
|
|
42
|
+
case "button":
|
|
43
|
+
return {
|
|
44
|
+
id,
|
|
45
|
+
type,
|
|
46
|
+
label: expectString(node.label, `${path}.label`),
|
|
47
|
+
action: parseToolAction(node.action, `${path}.action`),
|
|
48
|
+
};
|
|
49
|
+
case "text-input": {
|
|
50
|
+
const label = expectString(node.label, `${path}.label`);
|
|
51
|
+
const valueField = optionalString(node.value, `${path}.value`);
|
|
52
|
+
const binding = optionalString(node.binding, `${path}.binding`);
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
type,
|
|
56
|
+
label,
|
|
57
|
+
...(valueField === undefined ? {} : { value: valueField }),
|
|
58
|
+
...(binding === undefined ? {} : { binding }),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
default:
|
|
62
|
+
throw new A2uiParseError(`Unsupported node type at ${path}: ${type}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function parseToolAction(value, path) {
|
|
66
|
+
const action = expectObject(value, path);
|
|
67
|
+
const type = expectString(action.type, `${path}.type`);
|
|
68
|
+
if (type !== "tool") {
|
|
69
|
+
throw new A2uiParseError(`Unsupported action type at ${path}: ${type}`);
|
|
70
|
+
}
|
|
71
|
+
const arguments_ = action.arguments;
|
|
72
|
+
return {
|
|
73
|
+
type,
|
|
74
|
+
name: expectString(action.name, `${path}.name`),
|
|
75
|
+
...(arguments_ === undefined
|
|
76
|
+
? {}
|
|
77
|
+
: { arguments: expectJsonObject(arguments_, `${path}.arguments`) }),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function expectObject(value, path) {
|
|
81
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
82
|
+
throw new A2uiParseError(`Expected an object at ${path}`);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function expectArray(value, path) {
|
|
87
|
+
if (!Array.isArray(value)) {
|
|
88
|
+
throw new A2uiParseError(`Expected an array at ${path}`);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function expectString(value, path) {
|
|
93
|
+
if (typeof value !== "string") {
|
|
94
|
+
throw new A2uiParseError(`Expected a string at ${path}`);
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
function optionalString(value, path) {
|
|
99
|
+
return value === undefined ? undefined : expectString(value, path);
|
|
100
|
+
}
|
|
101
|
+
function expectJsonObject(value, path) {
|
|
102
|
+
const object = expectObject(value, path);
|
|
103
|
+
const result = {};
|
|
104
|
+
for (const [key, child] of Object.entries(object)) {
|
|
105
|
+
result[key] = expectJsonValue(child, `${path}.${key}`);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
function expectJsonValue(value, path) {
|
|
110
|
+
if (value === null ||
|
|
111
|
+
typeof value === "boolean" ||
|
|
112
|
+
typeof value === "number" ||
|
|
113
|
+
typeof value === "string") {
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
return value.map((child, index) => expectJsonValue(child, `${path}[${index}]`));
|
|
118
|
+
}
|
|
119
|
+
return expectJsonObject(value, path);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG,KAAc,CAAC;AAoC3C,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAuB;IACtD,IAAI,KAAK,GAAY,KAAK,CAAC;IAE3B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,KAAK,GAAG,IAAI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 1"
|
|
7
|
-
},
|
|
8
|
-
"keywords": [],
|
|
9
|
-
"author": "",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A2UI parsing and bindings for MCP Native.",
|
|
10
5
|
"license": "MIT",
|
|
11
|
-
"
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/pablospaniard/mcp-native.git",
|
|
9
|
+
"directory": "packages/a2ui"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@mcp-native/core": "^0.0.2"
|
|
30
|
+
}
|
|
12
31
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|