ain-ui 0.2.3 → 1.0.3
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/NOTICE +37 -0
- package/README.md +179 -77
- package/dist/agent.d.ts +131 -0
- package/dist/agent.js +802 -0
- package/dist/ainui.d.ts +15 -1
- package/dist/ainui.js +48 -10
- package/dist/basic.d.ts +5 -47
- package/dist/basic.js +11 -25
- package/dist/catalog/standard.gen.d.ts +5 -0
- package/dist/catalog/standard.gen.js +6 -0
- package/dist/catalog-v1.json +2560 -0
- package/dist/catalog.json +19917 -2061
- package/dist/chat.js +6 -7
- package/dist/expression.d.ts +23 -0
- package/dist/expression.js +222 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/macros.d.ts +12 -0
- package/dist/macros.js +57 -0
- package/dist/payment.js +6 -7
- package/dist/pickers.d.ts +158 -0
- package/dist/pickers.js +110 -0
- package/dist/protocol.d.ts +100 -0
- package/dist/protocol.js +232 -0
- package/dist/react/ain.d.ts +1 -0
- package/dist/react/ain.js +225 -0
- package/dist/react/catalog.d.ts +9 -0
- package/dist/react/catalog.js +23 -0
- package/dist/react/core.d.ts +84 -0
- package/dist/react/core.js +158 -0
- package/dist/react/functions.d.ts +2 -0
- package/dist/react/functions.js +29 -0
- package/dist/react/standard/composites.d.ts +1 -0
- package/dist/react/standard/composites.js +110 -0
- package/dist/react/standard/data.d.ts +1 -0
- package/dist/react/standard/data.js +481 -0
- package/dist/react/standard/feedback.d.ts +11 -0
- package/dist/react/standard/feedback.js +111 -0
- package/dist/react/standard/inputs.d.ts +5 -0
- package/dist/react/standard/inputs.js +467 -0
- package/dist/react/standard/layout.d.ts +5 -0
- package/dist/react/standard/layout.js +104 -0
- package/dist/react/standard/media.d.ts +33 -0
- package/dist/react/standard/media.js +208 -0
- package/dist/react/standard/rich.d.ts +1 -0
- package/dist/react/standard/rich.js +146 -0
- package/dist/react/standard/text.d.ts +9 -0
- package/dist/react/standard/text.js +209 -0
- package/dist/react/surface.d.ts +44 -0
- package/dist/react/surface.js +134 -0
- package/dist/react.d.ts +3 -35
- package/dist/react.js +3 -272
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +299 -4
- package/dist/styles.css +805 -20
- package/package.json +28 -11
package/dist/ainui.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type { SkillResult } from "./types.js";
|
|
|
23
23
|
import { type A2uiAction, type A2uiMessage } from "./basic.js";
|
|
24
24
|
export declare const AINUI_UPLOAD_MAX_BYTES: number;
|
|
25
25
|
export declare const AINUI_VERSION: "v1";
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const AINUI_PROTOCOL: "v2";
|
|
27
27
|
/** MCP request header a client sends to get AINUI surfaces. */
|
|
28
28
|
export declare const AINUI_HEADER = "x-ainui";
|
|
29
29
|
export type AinuiKind = "image" | "video" | "audio" | "pdf" | "folder" | "file";
|
|
@@ -160,8 +160,22 @@ export type AinuiReply =
|
|
|
160
160
|
| {
|
|
161
161
|
kind: "invalid";
|
|
162
162
|
error: string;
|
|
163
|
+
}
|
|
164
|
+
/** A picker action (PICKER_ACTIONS): passed through unchanged for the host to act on. */
|
|
165
|
+
| {
|
|
166
|
+
kind: "host";
|
|
167
|
+
action: A2uiAction;
|
|
163
168
|
};
|
|
164
169
|
export declare const AINUI_ACTIONS: readonly ["aindrive.open_drive", "aindrive.open", "aindrive.search", "aindrive.view", "aindrive.edit", "aindrive.new_file", "aindrive.save", "aindrive.delete", "aindrive.upload"];
|
|
170
|
+
/**
|
|
171
|
+
* Actions of the FilePicker / AgentPicker components (./pickers.ts, docs §5).
|
|
172
|
+
* They carry references, never bytes: `pick` returns the full FileRef/AgentRef
|
|
173
|
+
* objects the origin listed, `open`/`card` a public URL. The dispatcher hands
|
|
174
|
+
* them to the host untouched (`kind: "host"`) — deciding what a picked
|
|
175
|
+
* reference may be used for is the host's job, not the renderer's.
|
|
176
|
+
*/
|
|
177
|
+
export declare const PICKER_ACTIONS: readonly ["ainui.picker.scope", "ainui.picker.search", "ainui.picker.more", "ainui.picker.pick", "ainui.picker.open", "ainui.picker.card"];
|
|
178
|
+
export type PickerActionName = (typeof PICKER_ACTIONS)[number];
|
|
165
179
|
/**
|
|
166
180
|
* Answer an AINUI action. Multi-step actions run their follow-up server-side:
|
|
167
181
|
* new_file → editor on the new file, save → file view, delete → parent folder.
|
package/dist/ainui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A2UI_BASIC_CATALOG,
|
|
1
|
+
import { A2UI_BASIC_CATALOG, A2UI_BASIC_CATALOG_V09, A2UI_V09, AINUI_CATALOG, AINUI_CATALOG_V1, emitMessages, a2uiForSkill, baseOf, humanSize, parentOf, } from "./basic.js";
|
|
2
2
|
export const AINUI_UPLOAD_MAX_BYTES = 8 * 1024 * 1024;
|
|
3
3
|
export const AINUI_VERSION = "v1";
|
|
4
|
-
export const
|
|
4
|
+
export const AINUI_PROTOCOL = "v2";
|
|
5
5
|
/** MCP request header a client sends to get AINUI surfaces. */
|
|
6
6
|
export const AINUI_HEADER = "x-ainui";
|
|
7
7
|
/** Files larger than this open read-only (no edit button; aindrive.edit refuses). */
|
|
@@ -94,17 +94,39 @@ const column = (id, children) => ({ id, component: "Column", children });
|
|
|
94
94
|
const DRIVE = { path: "/drive_id" };
|
|
95
95
|
function ainuiSurface(prefix, components, data) {
|
|
96
96
|
const surfaceId = `aindrive-${prefix}-${Math.random().toString(36).slice(2, 10)}`;
|
|
97
|
-
return [
|
|
98
|
-
{ version:
|
|
99
|
-
{ version:
|
|
100
|
-
{ version:
|
|
101
|
-
];
|
|
97
|
+
return emitMessages([
|
|
98
|
+
{ version: A2UI_V09, createSurface: { surfaceId, catalogId: AINUI_CATALOG_V1 } },
|
|
99
|
+
{ version: A2UI_V09, updateComponents: { surfaceId, components } },
|
|
100
|
+
{ version: A2UI_V09, updateDataModel: { surfaceId, path: "/", value: data } },
|
|
101
|
+
]);
|
|
102
102
|
}
|
|
103
103
|
/** A basic-catalog surface is a valid AINUI surface: only the declared catalog changes. */
|
|
104
104
|
export function asAinui(messages) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
const moved = new Set();
|
|
106
|
+
// The basic catalog writes a heading as Markdown marks in Text; the AINUI catalog has Title for it.
|
|
107
|
+
const heading = (c) => {
|
|
108
|
+
if (c.component !== "Text")
|
|
109
|
+
return c;
|
|
110
|
+
const t = c.text;
|
|
111
|
+
const call = t && typeof t === "object" ? t : null;
|
|
112
|
+
const m = typeof t === "string" ? /^(#{1,5}) (.*)$/s.exec(t) : call?.["@call"] === "formatString" ? /^(#{1,5}) \$\{(.+)\}$/.exec(call.args?.value ?? "") : null;
|
|
113
|
+
if (!m)
|
|
114
|
+
return c.variant === "caption" ? { ...c, component: "Caption", variant: undefined } : c;
|
|
115
|
+
const size = ["2xl", "xl", "lg", "md", "sm"][m[1].length - 1];
|
|
116
|
+
return { ...c, component: "Title", size, text: typeof t === "string" ? m[2] : { "@path": m[2] } };
|
|
117
|
+
};
|
|
118
|
+
return messages.map((m) => {
|
|
119
|
+
// v0.9 output (setA2uiWireVersion): only the catalog changes, exactly as in AINUI v1
|
|
120
|
+
if ("createSurface" in m && m.createSurface.catalogId === A2UI_BASIC_CATALOG_V09)
|
|
121
|
+
return { ...m, createSurface: { ...m.createSurface, catalogId: AINUI_CATALOG_V1 } };
|
|
122
|
+
if ("createSurface" in m && m.createSurface.catalogId === A2UI_BASIC_CATALOG) {
|
|
123
|
+
moved.add(m.createSurface.surfaceId);
|
|
124
|
+
return { ...m, createSurface: { ...m.createSurface, catalogId: AINUI_CATALOG, ...(m.createSurface.components ? { components: m.createSurface.components.map(heading) } : {}) } };
|
|
125
|
+
}
|
|
126
|
+
if ("updateComponents" in m && moved.has(m.updateComponents.surfaceId))
|
|
127
|
+
return { ...m, updateComponents: { ...m.updateComponents, components: m.updateComponents.components.map(heading) } };
|
|
128
|
+
return m;
|
|
129
|
+
});
|
|
108
130
|
}
|
|
109
131
|
/** Root first; the last item is the current location (renderers draw it as plain text). */
|
|
110
132
|
export function crumbsFor(path, isDir, rootLabel = "/") {
|
|
@@ -303,6 +325,17 @@ export const AINUI_ACTIONS = [
|
|
|
303
325
|
"aindrive.open_drive", "aindrive.open", "aindrive.search", "aindrive.view",
|
|
304
326
|
"aindrive.edit", "aindrive.new_file", "aindrive.save", "aindrive.delete", "aindrive.upload",
|
|
305
327
|
];
|
|
328
|
+
/**
|
|
329
|
+
* Actions of the FilePicker / AgentPicker components (./pickers.ts, docs §5).
|
|
330
|
+
* They carry references, never bytes: `pick` returns the full FileRef/AgentRef
|
|
331
|
+
* objects the origin listed, `open`/`card` a public URL. The dispatcher hands
|
|
332
|
+
* them to the host untouched (`kind: "host"`) — deciding what a picked
|
|
333
|
+
* reference may be used for is the host's job, not the renderer's.
|
|
334
|
+
*/
|
|
335
|
+
export const PICKER_ACTIONS = [
|
|
336
|
+
"ainui.picker.scope", "ainui.picker.search", "ainui.picker.more",
|
|
337
|
+
"ainui.picker.pick", "ainui.picker.open", "ainui.picker.card",
|
|
338
|
+
];
|
|
306
339
|
const err = (code, message) => ({ kind: "err", code, message });
|
|
307
340
|
class Refused extends Error {
|
|
308
341
|
skill;
|
|
@@ -322,6 +355,11 @@ export async function dispatchAinuiAction(action, deps) {
|
|
|
322
355
|
const c = action.context ?? {};
|
|
323
356
|
const str = (v) => (typeof v === "string" ? v : "");
|
|
324
357
|
const drive_id = str(c.drive_id) || deps.driveId || "";
|
|
358
|
+
// Picker actions need no drive and run no skill: the renderer applies no
|
|
359
|
+
// permission logic to references (the origin already evaluated them at
|
|
360
|
+
// listing time), and neither does this dispatcher. The host decides.
|
|
361
|
+
if (PICKER_ACTIONS.includes(action.name))
|
|
362
|
+
return { kind: "host", action };
|
|
325
363
|
if (!AINUI_ACTIONS.includes(action.name))
|
|
326
364
|
return { kind: "invalid", error: `unknown action: ${action.name}` };
|
|
327
365
|
if (!drive_id)
|
package/dist/basic.d.ts
CHANGED
|
@@ -19,53 +19,17 @@
|
|
|
19
19
|
* in ./ainui.ts and is only sent to clients that opt in.
|
|
20
20
|
*/
|
|
21
21
|
import type { SkillResult } from "./types.js";
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
export declare const A2UI_BASIC_CATALOG = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
22
|
+
import { type A2uiAction, type A2uiMessage } from "./protocol.js";
|
|
23
|
+
export * from "./protocol.js";
|
|
25
24
|
/** A2A extension URI (A2UI over A2A), advertised in the agent card. */
|
|
26
|
-
export declare const A2UI_A2A_EXTENSION = "https://a2ui.org/a2a-extension/a2ui/
|
|
25
|
+
export declare const A2UI_A2A_EXTENSION = "https://a2ui.org/a2a-extension/a2ui/v1.0";
|
|
26
|
+
/** The v0.9 extension URI, still listed so older clients keep negotiating. */
|
|
27
|
+
export declare const A2UI_A2A_EXTENSION_V09 = "https://a2ui.org/a2a-extension/a2ui/v0.9";
|
|
27
28
|
/** AG-UI activity type used by @ag-ui/a2ui-middleware / CopilotKit. */
|
|
28
29
|
export declare const AGUI_A2UI_ACTIVITY = "a2ui-surface";
|
|
29
30
|
export declare const AGUI_A2UI_OPERATIONS_KEY = "a2ui_operations";
|
|
30
31
|
/** Where MCP tool results carry the surface for UI-only consumption (not shown to the model). */
|
|
31
32
|
export declare const A2UI_META_KEY = "ai.aindrive/a2ui";
|
|
32
|
-
export type A2uiComponent = {
|
|
33
|
-
id: string;
|
|
34
|
-
component: string;
|
|
35
|
-
} & Record<string, unknown>;
|
|
36
|
-
export type A2uiMessage = {
|
|
37
|
-
version: typeof A2UI_VERSION;
|
|
38
|
-
createSurface: {
|
|
39
|
-
surfaceId: string;
|
|
40
|
-
catalogId: string;
|
|
41
|
-
};
|
|
42
|
-
} | {
|
|
43
|
-
version: typeof A2UI_VERSION;
|
|
44
|
-
updateComponents: {
|
|
45
|
-
surfaceId: string;
|
|
46
|
-
components: A2uiComponent[];
|
|
47
|
-
};
|
|
48
|
-
} | {
|
|
49
|
-
version: typeof A2UI_VERSION;
|
|
50
|
-
updateDataModel: {
|
|
51
|
-
surfaceId: string;
|
|
52
|
-
path?: string;
|
|
53
|
-
value?: unknown;
|
|
54
|
-
};
|
|
55
|
-
} | {
|
|
56
|
-
version: typeof A2UI_VERSION;
|
|
57
|
-
deleteSurface: {
|
|
58
|
-
surfaceId: string;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
/** Client→server A2UI user action (v0.9 `action` object). */
|
|
62
|
-
export type A2uiAction = {
|
|
63
|
-
name: string;
|
|
64
|
-
surfaceId?: string;
|
|
65
|
-
sourceComponentId?: string;
|
|
66
|
-
timestamp?: string;
|
|
67
|
-
context?: Record<string, unknown>;
|
|
68
|
-
};
|
|
69
33
|
export declare function humanSize(n: unknown): string;
|
|
70
34
|
export declare const parentOf: (p: string) => string;
|
|
71
35
|
export declare const baseOf: (p: string) => string;
|
|
@@ -74,12 +38,6 @@ export declare const baseOf: (p: string) => string;
|
|
|
74
38
|
* ran against (from args or the pinned ctx); `args` are the skill arguments.
|
|
75
39
|
*/
|
|
76
40
|
export declare function a2uiForSkill(skill: string, args: Record<string, unknown>, result: SkillResult, driveId?: string): A2uiMessage[];
|
|
77
|
-
/**
|
|
78
|
-
* Accept the shapes renderers actually send: a v0.9 client event
|
|
79
|
-
* `{version, action}`, a bare `action` object, `{action}`, or AG-UI/CopilotKit's
|
|
80
|
-
* `{userAction}` (forwardedProps.a2uiAction).
|
|
81
|
-
*/
|
|
82
|
-
export declare function parseA2uiAction(input: unknown): A2uiAction | null;
|
|
83
41
|
export type SkillCall = {
|
|
84
42
|
skill: string;
|
|
85
43
|
args: Record<string, unknown>;
|
package/dist/basic.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export const A2UI_BASIC_CATALOG = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
1
|
+
import { A2UI_BASIC_CATALOG_V09, A2UI_V09, emitMessages } from "./protocol.js";
|
|
2
|
+
export * from "./protocol.js";
|
|
4
3
|
/** A2A extension URI (A2UI over A2A), advertised in the agent card. */
|
|
5
|
-
export const A2UI_A2A_EXTENSION = "https://a2ui.org/a2a-extension/a2ui/
|
|
4
|
+
export const A2UI_A2A_EXTENSION = "https://a2ui.org/a2a-extension/a2ui/v1.0";
|
|
5
|
+
/** The v0.9 extension URI, still listed so older clients keep negotiating. */
|
|
6
|
+
export const A2UI_A2A_EXTENSION_V09 = "https://a2ui.org/a2a-extension/a2ui/v0.9";
|
|
6
7
|
/** AG-UI activity type used by @ag-ui/a2ui-middleware / CopilotKit. */
|
|
7
8
|
export const AGUI_A2UI_ACTIVITY = "a2ui-surface";
|
|
8
9
|
export const AGUI_A2UI_OPERATIONS_KEY = "a2ui_operations";
|
|
@@ -15,11 +16,12 @@ const row = (id, children, extra = {}) => ({ id, component: "Row", children, ...
|
|
|
15
16
|
const column = (id, children) => ({ id, component: "Column", children });
|
|
16
17
|
function surface(prefix, components, data) {
|
|
17
18
|
const surfaceId = `aindrive-${prefix}-${Math.random().toString(36).slice(2, 10)}`;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{ version:
|
|
21
|
-
{ version:
|
|
22
|
-
|
|
19
|
+
// Written in the v0.9 layout the builders below use, sent as 1.0.
|
|
20
|
+
return emitMessages([
|
|
21
|
+
{ version: A2UI_V09, createSurface: { surfaceId, catalogId: A2UI_BASIC_CATALOG_V09 } },
|
|
22
|
+
{ version: A2UI_V09, updateComponents: { surfaceId, components } },
|
|
23
|
+
{ version: A2UI_V09, updateDataModel: { surfaceId, path: "/", value: data } },
|
|
24
|
+
]);
|
|
23
25
|
}
|
|
24
26
|
export function humanSize(n) {
|
|
25
27
|
if (typeof n !== "number" || !Number.isFinite(n))
|
|
@@ -178,22 +180,6 @@ export function a2uiForSkill(skill, args, result, driveId) {
|
|
|
178
180
|
return cardSurface("result", skill, result.text);
|
|
179
181
|
}
|
|
180
182
|
}
|
|
181
|
-
// ── actions (renderer → agent) ─────────────────────────────────────────────
|
|
182
|
-
/**
|
|
183
|
-
* Accept the shapes renderers actually send: a v0.9 client event
|
|
184
|
-
* `{version, action}`, a bare `action` object, `{action}`, or AG-UI/CopilotKit's
|
|
185
|
-
* `{userAction}` (forwardedProps.a2uiAction).
|
|
186
|
-
*/
|
|
187
|
-
export function parseA2uiAction(input) {
|
|
188
|
-
if (!input || typeof input !== "object")
|
|
189
|
-
return null;
|
|
190
|
-
const o = input;
|
|
191
|
-
const candidate = (o.action ?? o.userAction ?? o);
|
|
192
|
-
if (typeof candidate?.name !== "string")
|
|
193
|
-
return null;
|
|
194
|
-
const context = candidate.context && typeof candidate.context === "object" ? candidate.context : {};
|
|
195
|
-
return { ...candidate, name: candidate.name, context };
|
|
196
|
-
}
|
|
197
183
|
/** Map an aindrive A2UI action to the skill call that answers it. */
|
|
198
184
|
export function actionToSkill(action, fallbackDriveId) {
|
|
199
185
|
const c = action.context ?? {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The AINUI catalog document (A2UI 1.0): 92 components, 16 functions. */
|
|
2
|
+
export declare const AINUI_CATALOG_DOCUMENT: Record<string, any>;
|
|
3
|
+
/** Names of the standard components (the rest are AIN's own). */
|
|
4
|
+
export declare const RICH_COMPONENT_NAMES: readonly string[];
|
|
5
|
+
export declare const STANDARD_COMPONENT_NAMES: readonly string[];
|